mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 21:43:21 +00:00
caching: Add configuration class for post-migration cache flushing.
- To avoid redefining migrate manage command is added new application configuration class which emit post_migration signal. This signal require models module inside application and defined AppConfig Instance as signal sender. Documentation here: https://docs.djangoproject.com/en/1.8/ref/signals/#post-migrate. - Add AppConf subclass to __init__ zerver app file to make apllication load it by default. Fixes #1084.
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
# Load AppConfig app subclass by default on django applications initialization
|
||||
default_app_config = 'zerver.apps.ZerverConfig'
|
||||
|
||||
23
zerver/apps.py
Normal file
23
zerver/apps.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from __future__ import print_function
|
||||
|
||||
from django.apps import AppConfig
|
||||
from django.db.models.signals import post_migrate
|
||||
from django.core.cache import cache
|
||||
from django.conf import settings
|
||||
from typing import Any, Dict
|
||||
|
||||
import logging
|
||||
|
||||
def flush_cache(sender, **kwargs):
|
||||
# type: (AppConfig, **Any) -> None
|
||||
logging.info("Clearing memcached cache after migrations")
|
||||
cache.clear()
|
||||
|
||||
|
||||
class ZerverConfig(AppConfig):
|
||||
name = "zerver" # type: str
|
||||
|
||||
def ready(self):
|
||||
# type: () -> None
|
||||
if settings.POST_MIGRATION_CACHE_FLUSHING:
|
||||
post_migrate.connect(flush_cache, sender=self)
|
||||
@@ -36,3 +36,5 @@ SAVE_FRONTEND_STACKTRACES = True
|
||||
EVENT_LOGS_ENABLED = True
|
||||
SYSTEM_ONLY_REALMS = set() # type: Set[str]
|
||||
USING_PGROONGA = True
|
||||
# Flush cache after migration.
|
||||
POST_MIGRATION_CACHE_FLUSHING = True # type: bool
|
||||
|
||||
@@ -178,6 +178,7 @@ DEFAULT_SETTINGS = {'TWITTER_CONSUMER_KEY': '',
|
||||
'SYSTEM_ONLY_REALMS': {"zulip.com"},
|
||||
'FIRST_TIME_TOS_TEMPLATE': None,
|
||||
'USING_PGROONGA': False,
|
||||
'POST_MIGRATION_CACHE_FLUSHING': False,
|
||||
}
|
||||
|
||||
for setting_name, setting_val in six.iteritems(DEFAULT_SETTINGS):
|
||||
|
||||
Reference in New Issue
Block a user