Don't cache UserPresence info.

(imported from commit ff590bdf5d84bb9b3cedc561c2f2fbf7f7592a66)
This commit is contained in:
Steve Howell
2013-09-17 14:29:43 -04:00
parent c81c418478
commit 30b6f54a36
5 changed files with 4 additions and 28 deletions

View File

@@ -34,7 +34,7 @@ from django.utils import timezone
from zerver.lib.create_user import create_user
from zerver.lib import bugdown
from zerver.lib.cache import cache_with_key, cache_set, \
user_profile_by_email_cache_key, status_dict_cache_key, cache_set_many, \
user_profile_by_email_cache_key, cache_set_many, \
cache_delete, cache_delete_many, message_cache_key
from zerver.decorator import get_user_profile_by_email, json_to_list, JsonableError, \
statsd_increment
@@ -1367,7 +1367,6 @@ def gather_subscriptions(user_profile):
return (sorted(subscribed), sorted(unsubscribed))
@cache_with_key(status_dict_cache_key, timeout=60)
def get_status_dict(requesting_user_profile):
# Return no status info for MIT
if requesting_user_profile.realm.domain == 'mit.edu':

View File

@@ -250,19 +250,5 @@ def update_user_profile_cache(sender, **kwargs):
if kwargs['update_fields'] is None or "alert_words" in kwargs['update_fields']:
djcache.delete(KEY_PREFIX + realm_alert_words_cache_key(user_profile.realm))
def status_dict_cache_key_for_realm_id(realm_id):
return "status_dict:%d" % (realm_id,)
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.
user_profile = kwargs['instance'].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,)

View File

@@ -9,8 +9,7 @@ from zerver.models import Message, UserProfile, Stream, get_stream_cache_key, \
Huddle, huddle_hash_cache_key
from zerver.lib.cache import cache_with_key, cache_set, message_cache_key, \
user_profile_by_email_cache_key, user_profile_by_id_cache_key, \
get_memcached_time, get_memcached_requests, cache_set_many, \
status_dict_cache_key_for_realm_id
get_memcached_time, get_memcached_requests, cache_set_many
from django.utils.importlib import import_module
from django.contrib.sessions.models import Session
import logging
@@ -49,9 +48,6 @@ def huddle_cache_items(items_for_memcached, huddle):
def recipient_cache_items(items_for_memcached, recipient):
items_for_memcached[get_recipient_cache_key(recipient.type, recipient.type_id)] = (recipient,)
def presence_cache_items(items_for_memcached, status_dict):
items_for_memcached[status_dict_cache_key_for_realm_id(status_dict[0])] = (status_dict[1],)
session_engine = import_module(settings.SESSION_ENGINE)
def session_cache_items(items_for_memcached, session):
store = session_engine.SessionStore(session_key=session.session_key)

View File

@@ -6,7 +6,7 @@ from django.contrib.auth.models import AbstractBaseUser, UserManager, \
PermissionsMixin
from zerver.lib.cache import cache_with_key, update_user_profile_cache, \
user_profile_by_id_cache_key, user_profile_by_email_cache_key, \
update_user_presence_cache, generic_bulk_cached_fetch, cache_set, \
generic_bulk_cached_fetch, cache_set, \
display_recipient_cache_key
from zerver.lib.utils import make_safe_digest, generate_random_token
from django.db import transaction, IntegrityError
@@ -765,10 +765,6 @@ class UserPresence(models.Model):
class Meta:
unique_together = ("user_profile", "client")
# Flush the cached user status_dict whenever a user's presence
# changes
post_save.connect(update_user_presence_cache, sender=UserPresence)
class DefaultStream(models.Model):
realm = models.ForeignKey(Realm)
stream = models.ForeignKey(Stream)

View File

@@ -8,8 +8,7 @@ from zerver.models import Message, UserProfile, UserMessage, \
from zerver.decorator import JsonableError
from zerver.lib.cache import cache_get_many, message_cache_key, \
user_profile_by_id_cache_key, cache_save_user_profile, \
status_dict_cache_key_for_realm_id
user_profile_by_id_cache_key, cache_save_user_profile
from zerver.lib.cache_helpers import cache_save_message
from zerver.lib.queue import queue_json_publish
from zerver.lib.event_queue import get_client_descriptors_for_user