Caching of the latest document view work. May add database stress to other views. Commit ready for merge.

- Legacy-Id: 19489
This commit is contained in:
Robert Sparks 2021-10-28 21:25:15 +00:00
parent c0cbb79bf9
commit 6d74a83744
2 changed files with 19 additions and 10 deletions

View file

@ -24,8 +24,8 @@ def fill_in_telechat_date(docs, doc_dict=None, doc_ids=None):
seen = set() seen = set()
for e in TelechatDocEvent.objects.filter(doc__id__in=doc_ids, type="scheduled_for_telechat").order_by('-time'): for e in TelechatDocEvent.objects.filter(doc__id__in=doc_ids, type="scheduled_for_telechat").order_by('-time'):
if e.doc_id not in seen: if e.doc_id not in seen:
d = doc_dict[e.doc_id] #d = doc_dict[e.doc_id]
d.telechat_date = wrap_value(d.telechat_date(e)) #d.telechat_date = wrap_value(d.telechat_date(e))
seen.add(e.doc_id) seen.add(e.doc_id)
def fill_in_document_sessions(docs, doc_dict, doc_ids): def fill_in_document_sessions(docs, doc_dict, doc_ids):
@ -82,7 +82,7 @@ def fill_in_document_table_attributes(docs, have_telechat_date=False):
# misc # misc
for d in docs: for d in docs:
# emulate canonical name which is used by a lot of the utils # emulate canonical name which is used by a lot of the utils
d.canonical_name = wrap_value(rfc_aliases[d.pk] if d.pk in rfc_aliases else d.name) # d.canonical_name = wrap_value(rfc_aliases[d.pk] if d.pk in rfc_aliases else d.name)
if d.rfc_number() != None and d.latest_event_cache["published_rfc"]: if d.rfc_number() != None and d.latest_event_cache["published_rfc"]:
d.latest_revision_date = d.latest_event_cache["published_rfc"].time d.latest_revision_date = d.latest_event_cache["published_rfc"].time

View file

@ -39,7 +39,7 @@ import datetime
from django import forms from django import forms
from django.conf import settings from django.conf import settings
from django.core.cache import cache from django.core.cache import cache, caches
from django.urls import reverse as urlreverse from django.urls import reverse as urlreverse
from django.db.models import Q from django.db.models import Q
from django.http import Http404, HttpResponseBadRequest, HttpResponse, HttpResponseRedirect, QueryDict from django.http import Http404, HttpResponseBadRequest, HttpResponse, HttpResponseRedirect, QueryDict
@ -47,6 +47,7 @@ from django.shortcuts import render
from django.utils.cache import _generate_cache_key # type: ignore from django.utils.cache import _generate_cache_key # type: ignore
import debug # pyflakes:ignore import debug # pyflakes:ignore
from ietf.doc.models import ( Document, DocHistory, DocAlias, State, from ietf.doc.models import ( Document, DocHistory, DocAlias, State,
@ -485,12 +486,20 @@ def drafts_in_iesg_process(request):
}) })
def recent_drafts(request, days=7): def recent_drafts(request, days=7):
since = datetime.datetime.now()-datetime.timedelta(days=days) slowcache = caches['slowpages']
state = State.objects.get(type='draft', slug='active') cache_key = f'recentdraftsview{days}'
events = NewRevisionDocEvent.objects.filter(time__gt=since) cached_val = slowcache.get(cache_key)
names = [ e.doc.name for e in events ] if not cached_val:
docs = Document.objects.filter(name__in=names, states=state) since = datetime.datetime.now()-datetime.timedelta(days=days)
results, meta = prepare_document_table(request, docs, query={'sort':'-date', }, max_results=len(names)) state = State.objects.get(type='draft', slug='active')
events = NewRevisionDocEvent.objects.filter(time__gt=since)
names = [ e.doc.name for e in events ]
docs = Document.objects.filter(name__in=names, states=state)
results, meta = prepare_document_table(request, docs, query={'sort':'-date', }, max_results=len(names))
slowcache.set(cache_key, [docs, results, meta], 1800)
else:
[docs, results, meta] = cached_val
pages = 0 pages = 0
for doc in results: for doc in results:
pages += doc.pages or 0 pages += doc.pages or 0