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)
This commit is contained in:
Steve Howell
2014-01-28 12:03:06 -05:00
parent 0eed5d20d2
commit bbafd1dda8

View File

@@ -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,)