fix: memoize became_rfc. Address review comments.
This commit is contained in:
parent
bf50f88863
commit
3a733a36db
|
@ -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)]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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(
|
||||
[
|
||||
|
|
Loading…
Reference in a new issue