mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 08:26:11 +00:00
Use cache_set_many() in the flush_realm() code path.
The function update_user_profile_caches now operates on a list of user_profiles, so callers like flush_realm() can benefit from having a single cache_set_many() call. This slightly complicates the call from flush_user_profile(). (imported from commit e064871d849b873c6ca388f00d4f7afaba1bf222)
This commit is contained in:
@@ -248,17 +248,18 @@ def get_stream_cache_key(stream_name, realm):
|
||||
return "stream_by_realm_and_name:%s:%s" % (
|
||||
realm_id, make_safe_digest(stream_name.strip().lower()))
|
||||
|
||||
def update_user_profile_caches(user_profile):
|
||||
def update_user_profile_caches(user_profiles):
|
||||
items_for_memcached = {}
|
||||
items_for_memcached[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,)
|
||||
for user_profile in user_profiles:
|
||||
items_for_memcached[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,)
|
||||
cache_set_many(items_for_memcached)
|
||||
|
||||
# Called by models.py to flush the user_profile cache whenever we save
|
||||
# a user_profile object
|
||||
def flush_user_profile(sender, **kwargs):
|
||||
user_profile = kwargs['instance']
|
||||
update_user_profile_caches(user_profile)
|
||||
update_user_profile_caches([user_profile])
|
||||
|
||||
# Invalidate our active_users_in_realm info dict if any user has changed
|
||||
# name or email
|
||||
@@ -272,8 +273,8 @@ def flush_user_profile(sender, **kwargs):
|
||||
cache_delete(realm_alert_words_cache_key(user_profile.realm))
|
||||
|
||||
def flush_realm(realm):
|
||||
for user in realm.get_active_users():
|
||||
update_user_profile_caches(user)
|
||||
users = realm.get_active_users()
|
||||
update_user_profile_caches(users)
|
||||
|
||||
if realm.deactivated:
|
||||
cache_delete(active_user_dicts_in_realm_cache_key(realm))
|
||||
|
||||
Reference in New Issue
Block a user