Skip to content

Commit

Permalink
fix: Don't (re)sort obsoleted/updated info (#5391)
Browse files Browse the repository at this point in the history
* fix: Don't (re)sort obsoleted/updated info

Rebased against feat/postgres

* Update ietf/doc/utils_search.py

Co-authored-by: Robert Sparks <[email protected]>

* Update ietf/doc/utils_search.py

Co-authored-by: Robert Sparks <[email protected]>

* Update ietf/doc/utils_search.py

Co-authored-by: Robert Sparks <[email protected]>

* Fix review comments

---------

Co-authored-by: Robert Sparks <[email protected]>
  • Loading branch information
larseggert and rjsparks committed Jun 20, 2023
1 parent added86 commit a6cc12c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
33 changes: 26 additions & 7 deletions ietf/doc/utils_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,36 @@ def fill_in_document_table_attributes(docs, have_telechat_date=False):
d.obsoleted_by_list = []
d.updated_by_list = []

xed_by = RelatedDocument.objects.filter(target__name__in=list(rfc_aliases.values()),
relationship__in=("obs", "updates")).select_related('target')
rel_rfc_aliases = dict([ (a.document.id, re.sub(r"rfc(\d+)", r"RFC \1", a.name, flags=re.IGNORECASE)) for a in DocAlias.objects.filter(name__startswith="rfc", docs__id__in=[rel.source_id for rel in xed_by]) ])
# Revisit this block after RFCs become first-class Document objects
xed_by = list(
RelatedDocument.objects.filter(
target__name__in=list(rfc_aliases.values()),
relationship__in=("obs", "updates"),
).select_related("target")
)
rel_rfc_aliases = {
a.document.id: re.sub(r"rfc(\d+)", r"RFC \1", a.name, flags=re.IGNORECASE)
for a in DocAlias.objects.filter(
name__startswith="rfc", docs__id__in=[rel.source_id for rel in xed_by]
)
}
xed_by.sort(
key=lambda rel: int(
re.sub(
r"rfc\s*(\d+)",
r"\1",
rel_rfc_aliases[rel.source_id],
flags=re.IGNORECASE,
)
)
)
for rel in xed_by:
d = doc_dict[rel.target.document.id]
s = rel_rfc_aliases[rel.source_id]
if rel.relationship_id == "obs":
l = d.obsoleted_by_list
d.obsoleted_by_list.append(s)
elif rel.relationship_id == "updates":
l = d.updated_by_list
l.append(rel_rfc_aliases[rel.source_id])
l.sort()
d.updated_by_list.append(s)

def augment_docs_with_related_docs_info(docs):
"""Augment all documents with related documents information.
Expand Down
1 change: 1 addition & 0 deletions ietf/doc/views_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def interesting_doc_relations(doc):

that_doc_relationships = ('replaces', 'possibly_replaces', 'updates', 'obs')

# TODO: This returns the relationships in database order, which may not be the order we want to display them in.
interesting_relations_that = cls.objects.filter(target__docs=target, relationship__in=that_relationships).select_related('source')
interesting_relations_that_doc = cls.objects.filter(source=doc, relationship__in=that_doc_relationships).prefetch_related('target__docs')

Expand Down

0 comments on commit a6cc12c

Please sign in to comment.