change-email: Delete display recipient cache.

This commit is contained in:
Umair Khan 2017-01-23 16:11:04 +05:00 committed by Tim Abbott
parent 677b9e1ec6
commit c585fa6eb4

View File

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