Move flushing the display recipient cache to its own middleware

(imported from commit 27a6935a5830ef986b18de169d66dd86d273d064)
This commit is contained in:
Zev Benjamin 2013-11-08 15:13:34 -05:00
parent 53ec292022
commit 32ed5f9f42
2 changed files with 9 additions and 5 deletions

View File

@ -48,11 +48,6 @@ class LogRequests(object):
return "%.1fs" % (timedelta)
return "%.0fms" % (timedelta_ms(timedelta),)
# 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()
# For statsd timer name
if request.path == '/':
statsd_path = 'webreq'
@ -216,3 +211,11 @@ class RateLimitMiddleware(object):
if type(exception) == RateLimited:
resp = json_error("API usage exceeded rate limit, try again in %s secs" % (request._ratelimit_secs_to_freedom,), status=403)
return resp
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()
return response

View File

@ -156,6 +156,7 @@ MIDDLEWARE_CLASSES = (
'zerver.middleware.LogRequests',
'zerver.middleware.JsonErrorHandler',
'zerver.middleware.RateLimitMiddleware',
'zerver.middleware.FlushDisplayRecipientCache',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',