mirror of https://github.com/zulip/zulip.git
Improve names for per-request display recipient cache.
It incorrectly advertises itself as per-process. (imported from commit faf7ca7374d020058e80249bb16a4c6afbcb3e44)
This commit is contained in:
parent
ea1fefa5b5
commit
c91415f318
|
@ -7,7 +7,7 @@ from zerver.lib.utils import statsd
|
|||
from zerver.lib.queue import queue_json_publish
|
||||
from zerver.lib.cache import get_memcached_time, get_memcached_requests
|
||||
from zerver.lib.bugdown import get_bugdown_time, get_bugdown_requests
|
||||
from zerver.models import flush_per_process_display_recipient_cache
|
||||
from zerver.models import flush_per_request_caches
|
||||
from zerver.exceptions import RateLimited
|
||||
|
||||
import logging
|
||||
|
@ -265,8 +265,7 @@ class RateLimitMiddleware(object):
|
|||
|
||||
class FlushDisplayRecipientCache(object):
|
||||
def process_response(self, request, response):
|
||||
# We flush the recipient cache after every request, so it is
|
||||
# not shared at all between requests. We do this so all users
|
||||
# have a consistent view of stream name changes.
|
||||
flush_per_process_display_recipient_cache()
|
||||
# We flush the per-request caches after every request, so they
|
||||
# are not shared at all between requests.
|
||||
flush_per_request_caches()
|
||||
return response
|
||||
|
|
|
@ -34,12 +34,12 @@ def is_super_user(user):
|
|||
|
||||
# Doing 1000 memcached requests to get_display_recipient is quite slow,
|
||||
# so add a local cache as well as the memcached cache.
|
||||
per_process_display_recipient_cache = {}
|
||||
per_request_display_recipient_cache = {}
|
||||
def get_display_recipient_by_id(recipient_id, recipient_type, recipient_type_id):
|
||||
if recipient_id not in per_process_display_recipient_cache:
|
||||
if recipient_id not in per_request_display_recipient_cache:
|
||||
result = get_display_recipient_memcached(recipient_id, recipient_type, recipient_type_id)
|
||||
per_process_display_recipient_cache[recipient_id] = result
|
||||
return per_process_display_recipient_cache[recipient_id]
|
||||
per_request_display_recipient_cache[recipient_id] = result
|
||||
return per_request_display_recipient_cache[recipient_id]
|
||||
|
||||
def get_display_recipient(recipient):
|
||||
return get_display_recipient_by_id(
|
||||
|
@ -48,9 +48,9 @@ def get_display_recipient(recipient):
|
|||
recipient.type_id
|
||||
)
|
||||
|
||||
def flush_per_process_display_recipient_cache():
|
||||
global per_process_display_recipient_cache
|
||||
per_process_display_recipient_cache = {}
|
||||
def flush_per_request_caches():
|
||||
global per_request_display_recipient_cache
|
||||
per_request_display_recipient_cache = {}
|
||||
|
||||
@cache_with_key(lambda *args: display_recipient_cache_key(args[0]),
|
||||
timeout=3600*24*7)
|
||||
|
|
Loading…
Reference in New Issue