Skip to content

Commit 7e8aeee

Browse files
committed
Moved the caching of htmlized documents into Document.htmlized() in order to avoid caching failed htmliztions (usually because of a missing .txt file).
- Legacy-Id: 13227
1 parent 4c28fa2 commit 7e8aeee

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

ietf/doc/models.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from django.db import models
88
from django.core import checks
9+
from django.core.cache import caches
910
from django.core.exceptions import ValidationError
1011
from django.urls import reverse as urlreverse
1112
from django.core.validators import URLValidator
@@ -159,11 +160,12 @@ def get_file_name(self):
159160
def revisions(self):
160161
revisions = []
161162
doc = self.doc if isinstance(self, DocHistory) else self
162-
for e in doc.docevent_set.filter(type='new_revision').distinct().order_by("time", "id"):
163+
for e in doc.docevent_set.filter(type='new_revision').distinct():
163164
if e.rev and not e.rev in revisions:
164165
revisions.append(e.rev)
165166
if not doc.rev in revisions:
166167
revisions.append(doc.rev)
168+
revisions.sort()
167169
return revisions
168170

169171
def href(self, meeting=None):
@@ -435,11 +437,21 @@ def htmlized(self):
435437
return text
436438
if not name.endswith('.txt'):
437439
return None
438-
html = None
440+
html = ""
439441
if text:
440-
# The path here has to match the urlpattern for htmlized documents
441-
html = markup(text, path=settings.HTMLIZER_URL_PREFIX)
442-
#html = re.sub(r'<hr[^>]*/>','', html)
442+
cache = caches['htmlized']
443+
key = name.split('.')[0]
444+
html = cache.get(key)
445+
if not html:
446+
debug.say('cache miss for %s' % key)
447+
# The path here has to match the urlpattern for htmlized
448+
# documents in order to produce correct intra-document links
449+
html = markup(text, path=settings.HTMLIZER_URL_PREFIX)
450+
if html:
451+
debug.say('cache set for %s' % key)
452+
cache.set(key, html, settings.HTMLIZER_CACHE_TIME)
453+
else:
454+
debug.say('cache hit for %s' % key)
443455
return html
444456

445457
class Meta:

ietf/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ def skip_unreadable_post(record):
610610

611611
HTMLIZER_VERSION = 1
612612
HTMLIZER_URL_PREFIX = "/doc/html"
613+
HTMLIZER_CACHE_TIME = 60*60*24*14 # 14 days
613614

614615
IPR_EMAIL_FROM = 'ietf-ipr@ietf.org'
615616
AUDIO_IMPORT_EMAIL = ['agenda@ietf.org','ietf@meetecho.com']

0 commit comments

Comments
 (0)