Turn flush_realm() into a post-save hook for Realm.

(imported from commit 97e44b51e2b35b4b5b64b4008f6a8d3585a26e33)
This commit is contained in:
Steve Howell 2014-01-28 12:18:19 -05:00
parent 57030f53cc
commit c5edb58cd4
3 changed files with 9 additions and 5 deletions

View File

@ -3,7 +3,7 @@ from __future__ import absolute_import
from django.conf import settings from django.conf import settings
from django.core import validators from django.core import validators
from django.contrib.sessions.models import Session from django.contrib.sessions.models import Session
from zerver.lib.cache import flush_user_profile, flush_realm from zerver.lib.cache import flush_user_profile
from zerver.lib.context_managers import lockfile from zerver.lib.context_managers import lockfile
from zerver.models import Realm, RealmEmoji, Stream, UserProfile, UserActivity, \ from zerver.models import Realm, RealmEmoji, Stream, UserProfile, UserActivity, \
Subscription, Recipient, Message, UserMessage, valid_stream_name, \ Subscription, Recipient, Message, UserMessage, valid_stream_name, \
@ -167,8 +167,6 @@ def do_deactivate_realm(realm):
# notice when they try to log in. # notice when they try to log in.
delete_user_sessions(user) delete_user_sessions(user)
flush_realm(realm)
def do_deactivate_user(user_profile, log=True, _cascade=True): def do_deactivate_user(user_profile, log=True, _cascade=True):
if not user_profile.is_active: if not user_profile.is_active:
return return

View File

@ -272,7 +272,11 @@ def flush_user_profile(sender, **kwargs):
if kwargs['update_fields'] is None or "alert_words" in kwargs['update_fields']: if kwargs['update_fields'] is None or "alert_words" in kwargs['update_fields']:
cache_delete(realm_alert_words_cache_key(user_profile.realm)) cache_delete(realm_alert_words_cache_key(user_profile.realm))
def flush_realm(realm): # Called by models.py to flush various caches whenever we save
# a Realm object. The main tricky thing here is that Realm info is
# generally cached indirectly through user_profile objects.
def flush_realm(sender, **kwargs):
realm = kwargs['instance']
users = realm.get_active_users() users = realm.get_active_users()
update_user_profile_caches(users) update_user_profile_caches(users)

View File

@ -4,7 +4,7 @@ from django.db import models
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import AbstractBaseUser, UserManager, \ from django.contrib.auth.models import AbstractBaseUser, UserManager, \
PermissionsMixin PermissionsMixin
from zerver.lib.cache import cache_with_key, flush_user_profile, \ from zerver.lib.cache import cache_with_key, flush_user_profile, flush_realm, \
user_profile_by_id_cache_key, user_profile_by_email_cache_key, \ user_profile_by_id_cache_key, user_profile_by_email_cache_key, \
generic_bulk_cached_fetch, cache_set, update_stream_cache, \ generic_bulk_cached_fetch, cache_set, update_stream_cache, \
display_recipient_cache_key, cache_delete, \ display_recipient_cache_key, cache_delete, \
@ -140,6 +140,8 @@ class Realm(models.Model):
('administer', "Administer a realm"), ('administer', "Administer a realm"),
) )
post_save.connect(flush_realm, sender=Realm)
class RealmAlias(models.Model): class RealmAlias(models.Model):
realm = models.ForeignKey(Realm, null=True) realm = models.ForeignKey(Realm, null=True)
domain = models.CharField(max_length=80, db_index=True, unique=True) domain = models.CharField(max_length=80, db_index=True, unique=True)