diff --git a/config/settings.py b/config/settings.py index 4bb084fa..39dbc319 100755 --- a/config/settings.py +++ b/config/settings.py @@ -282,6 +282,8 @@ CELERY_BROKER_TRANSPORT_OPTIONS = { } CELERY_RESULT_BACKEND_THREAD_SAFE = True CELERY_TASK_ALWAYS_EAGER = env("CELERY_TASK_ALWAYS_EAGER", False) +# Reduce large amount of logging in redis. Usually 1 day. +CELERY_TASK_RESULT_EXPIRES = 3600 CACHES = { "default": { @@ -300,7 +302,9 @@ CACHES = { ENABLE_DB_CACHE = env.bool("ENABLE_DB_CACHE", default=False) # Default interval by which to clear the static content cache -CLEAR_STATIC_CONTENT_CACHE_DAYS = 7 +# New method: "never" clear, just overwrite, so that the id +# field doesn't expand without bounds. +CLEAR_STATIC_CONTENT_CACHE_DAYS = 7000 # Hyperkitty HYPERKITTY_DATABASE_NAME = env("HYPERKITTY_DATABASE_NAME", default="") diff --git a/core/views.py b/core/views.py index a525a408..2766bcd4 100644 --- a/core/views.py +++ b/core/views.py @@ -1,5 +1,7 @@ import os import re +from django.utils import timezone + from urllib.parse import urljoin import requests @@ -335,8 +337,17 @@ class BaseStaticContentTemplateView(TemplateView): return cached_result if cached_result else None def get_from_database(self, cache_key): + rendered_content_cache_time = 2628288 + dev_docs = ["static_content_develop/", "static_content_master/"] + for substring in dev_docs: + if substring in cache_key: + rendered_content_cache_time = 3600 + now = timezone.now() + start_time = now - timezone.timedelta(seconds=rendered_content_cache_time) try: - content_obj = RenderedContent.objects.get(cache_key=cache_key) + content_obj = RenderedContent.objects.filter(modified__gte=start_time).get( + cache_key=cache_key + ) return { "content": content_obj.content_html, "content_type": content_obj.content_type,