From bbafd1dda81244baf68de0ecf68c9bb2941f7ef2 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Tue, 28 Jan 2014 12:03:06 -0500 Subject: [PATCH] Have flush_realm() make O(1) cache_delete() calls in a couple places. For the realm-wide caches of active user dicts and alert words, just make a single call to cache_delete() when you are deactivating a realm. Before this change, we were doing O(N) cache_deletes as part of the code path through flush_user_profile(). Now we just call update_user_profile_caches() directly to clear the user_profile caches. This change also sets us up to turn flush_realm() into a post-save hook. (imported from commit 699b4ea226ae15fc8c402cb4bc64ff6bdc041fc2) --- zerver/lib/cache.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/zerver/lib/cache.py b/zerver/lib/cache.py index 2e4deea296..b06e448c87 100644 --- a/zerver/lib/cache.py +++ b/zerver/lib/cache.py @@ -273,7 +273,11 @@ def flush_user_profile(sender, **kwargs): def flush_realm(realm): for user in realm.get_active_users(): - flush_user_profile(None, instance=user, update_fields=None) + update_user_profile_caches(user) + + if realm.deactivated: + cache_delete(active_user_dicts_in_realm_cache_key(realm)) + cache_delete(realm_alert_words_cache_key(realm)) def realm_alert_words_cache_key(realm): return "realm_alert_words:%s" % (realm.domain,)