mirror of https://github.com/zulip/zulip.git
Populate cache of Stream objects on server restart.
(imported from commit 131eeddc5ebe5cc0db2554514a730d2750078012)
This commit is contained in:
parent
4fd1281f3c
commit
cc065a3c90
|
@ -1,10 +1,11 @@
|
|||
# This file needs to be different from cache.py because cache.py
|
||||
# cannot import anything from zephyr.models or we'd have an import
|
||||
# loop
|
||||
from zephyr.models import Message, UserProfile
|
||||
from zephyr.models import Message, UserProfile, Stream, get_stream_cache_key
|
||||
from zephyr.lib.cache import cache_with_key, djcache, message_cache_key, \
|
||||
user_profile_by_email_cache_key, user_profile_by_user_cache_key, \
|
||||
user_by_id_cache_key, user_profile_by_id_cache_key
|
||||
import logging
|
||||
|
||||
MESSAGE_CACHE_SIZE = 25000
|
||||
|
||||
|
@ -40,6 +41,17 @@ def populate_user_cache():
|
|||
|
||||
djcache.set_many(items_for_memcached, timeout=3600*24*7)
|
||||
|
||||
def populate_stream_cache():
|
||||
items_for_memcached = {}
|
||||
for stream in Stream.objects.select_related().all():
|
||||
items_for_memcached[get_stream_cache_key(stream.name, stream.realm_id)] = (stream,)
|
||||
|
||||
djcache.set_many(items_for_memcached, timeout=3600*24*7)
|
||||
|
||||
def fill_memcached_caches():
|
||||
populate_user_cache()
|
||||
logging.info("Succesfully populated user cache!")
|
||||
populate_stream_cache()
|
||||
logging.info("Succesfully populated stream cache!")
|
||||
populate_message_cache()
|
||||
logging.info("Succesfully populated mesasge cache!")
|
||||
|
|
Loading…
Reference in New Issue