Flush cache on all user presence updates.

(imported from commit 130eac36f9932350a29ed88f11dd3e2f6bf3f979)
This commit is contained in:
Steve Howell
2013-09-15 14:20:33 -04:00
parent 7868787ae0
commit 83e517fcf9

View File

@@ -257,10 +257,13 @@ def status_dict_cache_key(user_profile):
return status_dict_cache_key_for_realm_id(user_profile.realm_id) return status_dict_cache_key_for_realm_id(user_profile.realm_id)
def update_user_presence_cache(sender, **kwargs): def update_user_presence_cache(sender, **kwargs):
# For any status update, flush the user's realm's entry in the
# UserPresence cache to avoid giving out stale state. Since we
# get a lot of presence updates, we are likely to get cache misses
# when new messages come in, but the query is pretty quick, and we
# no longer have the issue of Tornado needing to go the cache or DB
# to get presence info.
user_profile = kwargs['instance'].user_profile user_profile = kwargs['instance'].user_profile
if kwargs['update_fields'] is None or "status" in kwargs['update_fields']:
# If the status of the user changed, flush the user's realm's
# entry in the UserPresence cache to avoid giving out stale state
djcache.delete(KEY_PREFIX + status_dict_cache_key(user_profile)) djcache.delete(KEY_PREFIX + status_dict_cache_key(user_profile))
def realm_alert_words_cache_key(realm): def realm_alert_words_cache_key(realm):