s/items_for_memcached/items_for_remote_cache/g

This commit is contained in:
Ryan Moore
2016-03-30 18:21:05 -07:00
committed by Tim Abbott
parent 93b3feda43
commit 9f29b80f8a
3 changed files with 36 additions and 36 deletions

View File

@@ -2266,16 +2266,16 @@ def do_update_message(user_profile, message_id, subject, propagate_mode, content
# Update the message as stored in the (deprecated) message # Update the message as stored in the (deprecated) message
# cache (for shunting the message over to Tornado in the old # cache (for shunting the message over to Tornado in the old
# get_messages API) and also the to_dict caches. # get_messages API) and also the to_dict caches.
items_for_memcached = {} items_for_remote_cache = {}
event['message_ids'] = [] event['message_ids'] = []
for changed_message in changed_messages: for changed_message in changed_messages:
event['message_ids'].append(changed_message.id) event['message_ids'].append(changed_message.id)
items_for_memcached[message_cache_key(changed_message.id)] = (changed_message,) items_for_remote_cache[message_cache_key(changed_message.id)] = (changed_message,)
items_for_memcached[to_dict_cache_key(changed_message, True)] = \ items_for_remote_cache[to_dict_cache_key(changed_message, True)] = \
(stringify_message_dict(changed_message.to_dict_uncached(apply_markdown=True)),) (stringify_message_dict(changed_message.to_dict_uncached(apply_markdown=True)),)
items_for_memcached[to_dict_cache_key(changed_message, False)] = \ items_for_remote_cache[to_dict_cache_key(changed_message, False)] = \
(stringify_message_dict(changed_message.to_dict_uncached(apply_markdown=False)),) (stringify_message_dict(changed_message.to_dict_uncached(apply_markdown=False)),)
cache_set_many(items_for_memcached) cache_set_many(items_for_remote_cache)
def user_info(um): def user_info(um):
return { return {

View File

@@ -194,14 +194,14 @@ def generic_bulk_cached_fetch(cache_key_function, query_function, object_ids,
cache_keys[object_id] not in cached_objects] cache_keys[object_id] not in cached_objects]
db_objects = query_function(needed_ids) db_objects = query_function(needed_ids)
items_for_memcached = {} items_for_remote_cache = {}
for obj in db_objects: for obj in db_objects:
key = cache_keys[id_fetcher(obj)] key = cache_keys[id_fetcher(obj)]
item = cache_transformer(obj) item = cache_transformer(obj)
items_for_memcached[key] = (setter(item),) items_for_remote_cache[key] = (setter(item),)
cached_objects[key] = item cached_objects[key] = item
if len(items_for_memcached) > 0: if len(items_for_remote_cache) > 0:
cache_set_many(items_for_memcached) cache_set_many(items_for_remote_cache)
return dict((object_id, cached_objects[cache_keys[object_id]]) for object_id in object_ids return dict((object_id, cached_objects[cache_keys[object_id]]) for object_id in object_ids
if cache_keys[object_id] in cached_objects) if cache_keys[object_id] in cached_objects)
@@ -255,11 +255,11 @@ def get_stream_cache_key(stream_name, realm):
realm_id, make_safe_digest(stream_name.strip().lower())) realm_id, make_safe_digest(stream_name.strip().lower()))
def update_user_profile_caches(user_profiles): def update_user_profile_caches(user_profiles):
items_for_memcached = {} items_for_remote_cache = {}
for user_profile in user_profiles: for user_profile in user_profiles:
items_for_memcached[user_profile_by_email_cache_key(user_profile.email)] = (user_profile,) items_for_remote_cache[user_profile_by_email_cache_key(user_profile.email)] = (user_profile,)
items_for_memcached[user_profile_by_id_cache_key(user_profile.id)] = (user_profile,) items_for_remote_cache[user_profile_by_id_cache_key(user_profile.id)] = (user_profile,)
cache_set_many(items_for_memcached) cache_set_many(items_for_remote_cache)
# Called by models.py to flush the user_profile cache whenever we save # Called by models.py to flush the user_profile cache whenever we save
# a user_profile object # a user_profile object
@@ -306,9 +306,9 @@ def realm_alert_words_cache_key(realm):
def flush_stream(sender, **kwargs): def flush_stream(sender, **kwargs):
from zerver.models import UserProfile from zerver.models import UserProfile
stream = kwargs['instance'] stream = kwargs['instance']
items_for_memcached = {} items_for_remote_cache = {}
items_for_memcached[get_stream_cache_key(stream.name, stream.realm)] = (stream,) items_for_remote_cache[get_stream_cache_key(stream.name, stream.realm)] = (stream,)
cache_set_many(items_for_memcached) cache_set_many(items_for_remote_cache)
if kwargs['update_fields'] is None or 'name' in kwargs['update_fields'] and \ if kwargs['update_fields'] is None or 'name' in kwargs['update_fields'] and \
UserProfile.objects.filter( UserProfile.objects.filter(

View File

@@ -32,29 +32,29 @@ def message_fetch_objects():
return Message.objects.select_related().filter(~Q(sender__email='tabbott/extra@mit.edu'), return Message.objects.select_related().filter(~Q(sender__email='tabbott/extra@mit.edu'),
id__gt=max_id - MESSAGE_CACHE_SIZE) id__gt=max_id - MESSAGE_CACHE_SIZE)
def message_cache_items(items_for_memcached, message): def message_cache_items(items_for_remote_cache, message):
items_for_memcached[message_cache_key(message.id)] = (message,) items_for_remote_cache[message_cache_key(message.id)] = (message,)
def user_cache_items(items_for_memcached, user_profile): def user_cache_items(items_for_remote_cache, user_profile):
items_for_memcached[user_profile_by_email_cache_key(user_profile.email)] = (user_profile,) items_for_remote_cache[user_profile_by_email_cache_key(user_profile.email)] = (user_profile,)
items_for_memcached[user_profile_by_id_cache_key(user_profile.id)] = (user_profile,) items_for_remote_cache[user_profile_by_id_cache_key(user_profile.id)] = (user_profile,)
def stream_cache_items(items_for_memcached, stream): def stream_cache_items(items_for_remote_cache, stream):
items_for_memcached[get_stream_cache_key(stream.name, stream.realm_id)] = (stream,) items_for_remote_cache[get_stream_cache_key(stream.name, stream.realm_id)] = (stream,)
def client_cache_items(items_for_memcached, client): def client_cache_items(items_for_remote_cache, client):
items_for_memcached[get_client_cache_key(client.name)] = (client,) items_for_remote_cache[get_client_cache_key(client.name)] = (client,)
def huddle_cache_items(items_for_memcached, huddle): def huddle_cache_items(items_for_remote_cache, huddle):
items_for_memcached[huddle_hash_cache_key(huddle.huddle_hash)] = (huddle,) items_for_remote_cache[huddle_hash_cache_key(huddle.huddle_hash)] = (huddle,)
def recipient_cache_items(items_for_memcached, recipient): def recipient_cache_items(items_for_remote_cache, recipient):
items_for_memcached[get_recipient_cache_key(recipient.type, recipient.type_id)] = (recipient,) items_for_remote_cache[get_recipient_cache_key(recipient.type, recipient.type_id)] = (recipient,)
session_engine = import_module(settings.SESSION_ENGINE) session_engine = import_module(settings.SESSION_ENGINE)
def session_cache_items(items_for_memcached, session): def session_cache_items(items_for_remote_cache, session):
store = session_engine.SessionStore(session_key=session.session_key) store = session_engine.SessionStore(session_key=session.session_key)
items_for_memcached[store.cache_key] = store.decode(session.session_data) items_for_remote_cache[store.cache_key] = store.decode(session.session_data)
# Format is (objects query, items filler function, timeout, batch size) # Format is (objects query, items filler function, timeout, batch size)
# #
@@ -75,16 +75,16 @@ cache_fillers = {
def fill_memcached_cache(cache): def fill_memcached_cache(cache):
memcached_time_start = get_memcached_time() memcached_time_start = get_memcached_time()
memcached_requests_start = get_memcached_requests() memcached_requests_start = get_memcached_requests()
items_for_memcached = {} items_for_remote_cache = {}
(objects, items_filler, timeout, batch_size) = cache_fillers[cache] (objects, items_filler, timeout, batch_size) = cache_fillers[cache]
count = 0 count = 0
for obj in objects(): for obj in objects():
items_filler(items_for_memcached, obj) items_filler(items_for_remote_cache, obj)
count += 1 count += 1
if (count % batch_size == 0): if (count % batch_size == 0):
cache_set_many(items_for_memcached, timeout=3600*24) cache_set_many(items_for_remote_cache, timeout=3600*24)
items_for_memcached = {} items_for_remote_cache = {}
cache_set_many(items_for_memcached, timeout=3600*24*7) cache_set_many(items_for_remote_cache, timeout=3600*24*7)
logging.info("Succesfully populated %s cache! Consumed %s memcached queries (%s time)" % \ logging.info("Succesfully populated %s cache! Consumed %s memcached queries (%s time)" % \
(cache, get_memcached_requests() - memcached_requests_start, (cache, get_memcached_requests() - memcached_requests_start,
round(get_memcached_time() - memcached_time_start, 2))) round(get_memcached_time() - memcached_time_start, 2)))