mirror of
https://github.com/zulip/zulip.git
synced 2025-11-16 03:41:58 +00:00
Previously, we were fetching Message.objects.select_related() from the database, even if we actually ended up fetching the message dicts from memcached and thus not actually using them. Especially in the cached case, this resulted in a lot of overhead where the Django ORM put together Message objects with lots of data in them that were never used. This commit switches the model to only fetch the full message objects from the database for those messages which are not found in the memcached caches. Here are the timings for get_old_messages before this patch was applied: (cached) 127ms (db: 42ms/2q) /json/get_old_messages (starnine@mit.edu via website) 385ms (db: 105ms/1q) /json/get_old_messages (starnine@mit.edu via website) (uncached) 315ms (mem: 6ms/41) (db: 90ms/22q) /json/get_old_messages (starnine@mit.edu via website) 507ms (db: 94ms/14q) /json/get_old_messages (starnine@mit.edu via website) Here are the timings for get_old_messages after this patch was applied: (cached) 80ms (db: 9ms/2q) /json/get_old_messages (starnine@mit.edu via website) 133ms (db: 4ms/1q) /json/get_old_messages (starnine@mit.edu via website) (uncached) 230ms (mem: 9ms/41) (db: 48ms/23q) /json/get_old_messages (starnine@mit.edu via website) 385ms (db: 55ms/15q) /json/get_old_messages (starnine@mit.edu via website) (imported from commit c4748513392a906393314aa7cd41d98a69865411)
20 KiB
20 KiB