fix: memoize became_rfc. Address review comments.

This commit is contained in:
Robert Sparks 2023-09-13 14:07:40 -05:00
parent bf50f88863
commit 3a733a36db
No known key found for this signature in database
GPG key ID: 6E2A6A5775F91318
3 changed files with 16 additions and 13 deletions

View file

@ -25,14 +25,10 @@ def forward(apps, schema_editor):
).exists()
def reverse(apps, schema_editor):
# there is no going back
raise NotImplementedError
class Migration(migrations.Migration):
dependencies = [
("doc", "0015_delete_docalias"),
]
operations = [migrations.RunPython(forward, reverse)]
# There is no going back
operations = [migrations.RunPython(forward)]

View file

@ -666,13 +666,16 @@ class DocumentInfo(models.Model):
)
def became_rfc(self):
doc = self if isinstance(self, Document) else self.doc
return next(iter(doc.related_that_doc("became_rfc")), None)
if not hasattr(self, "_cached_became_rfc"):
doc = self if isinstance(self, Document) else self.doc
self._cached_became_rfc = next(iter(doc.related_that_doc("became_rfc")), None)
return self._cached_became_rfc
def came_from_draft(self):
doc = self if isinstance(self, Document) else self.doc
return next(iter(doc.related_that("became_rfc")), None)
if not hasattr(self, "_cached_came_from_draft"):
doc = self if isinstance(self, Document) else self.doc
self.cached_came_from_draft = next(iter(doc.related_that("became_rfc")), None)
return self._cached_came_from_draft
class Meta:
abstract = True

View file

@ -195,6 +195,8 @@ def document_main(request, name, rev=None, document_html=False):
doc = get_object_or_404(Document.objects.select_related(), name=name)
log.assertion('doc.type_id!="rfc" or doc.name.startswith("rfc")')
# take care of possible redirections
if document_html is False and rev is None:
became_rfc = doc.became_rfc()
@ -1126,8 +1128,10 @@ def document_email(request,name):
def get_diff_revisions(request, name, doc):
""" returns list of (name, rev, time, url, is_this_doc, is_previous_doc)
ordered by -time for use by forms used to get to the diff tools.
""" Calculate what to offer for diff comparisons
returns list of (name, rev, time, url, is_this_doc, is_previous_doc)
ordered by -time for use by forms used to get to the diff tools.
"""
diffable = any(
[