Populate cache of Huddle objects on server restart.

(imported from commit 3214cfa70d0de01c42028a9d025f7607f609081b)
This commit is contained in:
Tim Abbott
2013-03-26 13:20:47 -04:00
parent 8b2cb6472b
commit 8fbc98601b

View File

@@ -2,7 +2,8 @@
# cannot import anything from zephyr.models or we'd have an import
# loop
from zephyr.models import Message, UserProfile, Stream, get_stream_cache_key, \
Recipient, get_recipient_cache_key, Client, get_client_cache_key
Recipient, get_recipient_cache_key, Client, get_client_cache_key, \
Huddle, huddle_hash_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
@@ -56,6 +57,13 @@ def populate_client_cache():
djcache.set_many(items_for_memcached, timeout=3600*24*7)
def populate_huddle_cache():
items_for_memcached = {}
for huddle in Huddle.objects.select_related().all():
items_for_memcached[huddle_hash_cache_key(huddle.huddle_hash)] = (huddle,)
djcache.set_many(items_for_memcached, timeout=3600*24*7)
def populate_recipient_cache():
items_for_memcached = {}
for recipient in Recipient.objects.select_related().all():
@@ -69,6 +77,7 @@ cache_fillers = {
'recipient': populate_recipient_cache,
'stream': populate_stream_cache,
'message': populate_message_cache,
'huddle': populate_huddle_cache,
}
def fill_memcached_cache(cache):