Skip to content

Commit f8139ec

Browse files
committed
DB caching reuses the same id field
1 parent 8294d3f commit f8139ec

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

config/settings.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@
282282
}
283283
CELERY_RESULT_BACKEND_THREAD_SAFE = True
284284
CELERY_TASK_ALWAYS_EAGER = env("CELERY_TASK_ALWAYS_EAGER", False)
285+
# Reduce large amount of logging in redis. Default 1 day.
286+
CELERY_TASK_RESULT_EXPIRES = 3600
285287

286288
CACHES = {
287289
"default": {
@@ -300,7 +302,9 @@
300302
ENABLE_DB_CACHE = env.bool("ENABLE_DB_CACHE", default=False)
301303

302304
# Default interval by which to clear the static content cache
303-
CLEAR_STATIC_CONTENT_CACHE_DAYS = 7
305+
# New method: "never" clear, just overwrite, so that the id
306+
# field doesn't expand without bounds.
307+
CLEAR_STATIC_CONTENT_CACHE_DAYS = 7000000
304308

305309
# Hyperkitty
306310
HYPERKITTY_DATABASE_NAME = env("HYPERKITTY_DATABASE_NAME", default="")

core/views.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import os
22
import re
3+
import datetime
4+
from django.utils import timezone
5+
import pytz
6+
37
from urllib.parse import urljoin
48

59
import requests
@@ -335,8 +339,17 @@ def get_from_cache(self, static_content_cache, cache_key):
335339
return cached_result if cached_result else None
336340

337341
def get_from_database(self, cache_key):
342+
rendered_content_cache_time = 2628288
343+
dev_docs = ["static_content_develop/", "static_content_master/"]
344+
for substring in dev_docs:
345+
if substring in cache_key:
346+
rendered_content_cache_time = 120 # Switch this to 3600
347+
now = timezone.now()
348+
start_time = now - datetime.timedelta(seconds=rendered_content_cache_time)
338349
try:
339-
content_obj = RenderedContent.objects.get(cache_key=cache_key)
350+
content_obj = RenderedContent.objects.filter(modified__gte=start_time).get(
351+
cache_key=cache_key
352+
)
340353
return {
341354
"content": content_obj.content_html,
342355
"content_type": content_obj.content_type,

0 commit comments

Comments
 (0)