Skip to content

Commit aa27ba9

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

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-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 = 7000
304308

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

core/views.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import os
22
import re
3+
from django.utils import timezone
4+
35
from urllib.parse import urljoin
46

57
import requests
@@ -335,8 +337,17 @@ def get_from_cache(self, static_content_cache, cache_key):
335337
return cached_result if cached_result else None
336338

337339
def get_from_database(self, cache_key):
340+
rendered_content_cache_time = 2628288
341+
dev_docs = ["static_content_develop/", "static_content_master/"]
342+
for substring in dev_docs:
343+
if substring in cache_key:
344+
rendered_content_cache_time = 120 # Switch this to 3600
345+
now = timezone.now()
346+
start_time = now - timezone.timedelta(seconds=rendered_content_cache_time)
338347
try:
339-
content_obj = RenderedContent.objects.get(cache_key=cache_key)
348+
content_obj = RenderedContent.objects.filter(modified__gte=start_time).get(
349+
cache_key=cache_key
350+
)
340351
return {
341352
"content": content_obj.content_html,
342353
"content_type": content_obj.content_type,

0 commit comments

Comments
 (0)