diff --git a/zerver/lib/cache.py b/zerver/lib/cache.py index 9093bd1413..eb0dbe84cf 100644 --- a/zerver/lib/cache.py +++ b/zerver/lib/cache.py @@ -257,11 +257,14 @@ def status_dict_cache_key(user_profile): return status_dict_cache_key_for_realm_id(user_profile.realm_id) 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 - 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): return "realm_alert_words:%s" % (realm.domain,)