2016-10-17 18:11:16 +02:00
|
|
|
import logging
|
2019-02-23 00:47:38 +01:00
|
|
|
from typing import Any
|
2016-10-17 18:11:16 +02:00
|
|
|
|
2017-11-16 00:50:28 +01:00
|
|
|
from django.apps import AppConfig
|
|
|
|
from django.conf import settings
|
|
|
|
from django.core.cache import cache
|
|
|
|
from django.db.models.signals import post_migrate
|
2017-01-30 23:19:38 +01:00
|
|
|
|
2017-11-27 07:33:05 +01:00
|
|
|
def flush_cache(sender: AppConfig, **kwargs: Any) -> None:
|
2016-10-17 18:11:16 +02:00
|
|
|
logging.info("Clearing memcached cache after migrations")
|
|
|
|
cache.clear()
|
|
|
|
|
|
|
|
|
|
|
|
class ZerverConfig(AppConfig):
|
|
|
|
name = "zerver" # type: str
|
|
|
|
|
2017-11-27 07:33:05 +01:00
|
|
|
def ready(self) -> None:
|
2019-02-03 08:02:55 +01:00
|
|
|
# We import zerver.signals here for the side effect of
|
|
|
|
# registering the user_logged_in signal receiver. This import
|
|
|
|
# needs to be here (rather than e.g. at top-of-file) to avoid
|
|
|
|
# running that code too early in Django's setup process, but
|
|
|
|
# in any case, this is an intentionally unused import.
|
2017-01-30 23:19:38 +01:00
|
|
|
import zerver.signals
|
2019-02-23 00:48:42 +01:00
|
|
|
zerver.signals
|
2017-01-30 23:19:38 +01:00
|
|
|
|
2016-10-17 18:11:16 +02:00
|
|
|
if settings.POST_MIGRATION_CACHE_FLUSHING:
|
|
|
|
post_migrate.connect(flush_cache, sender=self)
|