From c585fa6eb4100d593d90ad47c3134aede94486a7 Mon Sep 17 00:00:00 2001 From: Umair Khan Date: Mon, 23 Jan 2017 16:11:04 +0500 Subject: [PATCH] change-email: Delete display recipient cache. --- zerver/lib/cache.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/zerver/lib/cache.py b/zerver/lib/cache.py index 7b63a8e470..709e12e1bd 100644 --- a/zerver/lib/cache.py +++ b/zerver/lib/cache.py @@ -346,6 +346,14 @@ def delete_user_profile_caches(user_profiles): cache_delete_many(keys) +def delete_display_recipient_cache(user_profile): + # type: (UserProfile) -> None + from zerver.models import Subscription # We need to import here to avoid cyclic dependency. + recipient_ids = Subscription.objects.filter(user_profile=user_profile) + recipient_ids = recipient_ids.values_list('recipient_id', flat=True) + keys = [display_recipient_cache_key(rid) for rid in recipient_ids] + cache_delete_many(keys) + # Called by models.py to flush the user_profile cache whenever we save # a user_profile object def flush_user_profile(sender, **kwargs): @@ -360,6 +368,10 @@ def flush_user_profile(sender, **kwargs): set(kwargs['update_fields'])) > 0: cache_delete(active_user_dicts_in_realm_cache_key(user_profile.realm)) + if kwargs.get('updated_fields') is None or \ + 'email' in kwargs['update_fields']: + delete_display_recipient_cache(user_profile) + # Invalidate our active_bots_in_realm info dict if any bot has # changed the fields in the dict or become (in)active if user_profile.is_bot and (kwargs['update_fields'] is None or