mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 00:46:03 +00:00
tornado: Fill the message memcached in a child process.
(imported from commit 3a7b4c0f4aad37319f4cfa7892709e99883f6a87)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
from zephyr.models import Message
|
||||
from zephyr.lib.cache import cache_with_key, djcache
|
||||
|
||||
MESSAGE_CACHE_SIZE = 25000
|
||||
|
||||
def message_cache_key(message_id):
|
||||
return "message:%d" % (message_id,)
|
||||
|
||||
@@ -12,11 +14,12 @@ def cache_get_message(message_id):
|
||||
return Message.objects.select_related("client", "sender").get(id=message_id)
|
||||
|
||||
# Called on Tornado startup to ensure our message cache isn't empty
|
||||
def populate_message_cache(count):
|
||||
def populate_message_cache():
|
||||
max_message_id = 0
|
||||
min_message_id = 0
|
||||
messages_for_memcached = {}
|
||||
for m in Message.objects.select_related("sender", "client").all().order_by("-id")[0:count]:
|
||||
for m in Message.objects.select_related("sender", "client").all().order_by(
|
||||
"-id")[0:MESSAGE_CACHE_SIZE]:
|
||||
max_message_id = max(m.id, max_message_id)
|
||||
min_message_id = min(m.id, min_message_id)
|
||||
messages_for_memcached[message_cache_key(m.id)] = (m,)
|
||||
|
||||
Reference in New Issue
Block a user