diff --git a/ietf/doc/feeds.py b/ietf/doc/feeds.py index 7885e75e3..92871efc3 100644 --- a/ietf/doc/feeds.py +++ b/ietf/doc/feeds.py @@ -45,7 +45,7 @@ class DocumentChangesFeed(Feed): return "History of change entries for %s." % obj.display_name() def items(self, obj): - events = obj.docevent_set.all().order_by("-time","-id") + events = obj.docevent_set.all().order_by("-time","-id").select_related("by", "newrevisiondocevent", "submissiondocevent") augment_events_with_revision(obj, events) return events diff --git a/ietf/doc/utils.py b/ietf/doc/utils.py index 14dfb9513..b2e65066a 100644 --- a/ietf/doc/utils.py +++ b/ietf/doc/utils.py @@ -17,6 +17,7 @@ from zoneinfo import ZoneInfo from django.conf import settings from django.contrib import messages +from django.db.models import QuerySet from django.forms import ValidationError from django.http import Http404 from django.template.loader import render_to_string @@ -344,11 +345,18 @@ def augment_events_with_revision(doc, events): """Take a set of events for doc and add a .rev attribute with the revision they refer to by checking NewRevisionDocEvents.""" - event_revisions = list(NewRevisionDocEvent.objects.filter(doc=doc).order_by('time', 'id').values('id', 'rev', 'time')) + if isinstance(events, QuerySet): + qs = events.filter(newrevisiondocevent__isnull=False) + else: + qs = NewRevisionDocEvent.objects.filter(doc=doc) + event_revisions = list(qs.order_by('time', 'id').values('id', 'rev', 'time')) if doc.type_id == "draft" and doc.get_state_slug() == "rfc": # add fake "RFC" revision - e = doc.latest_event(type="published_rfc") + if isinstance(events, QuerySet): + e = events.filter(type="published_rfc").order_by('time').last() + else: + e = doc.latest_event(type="published_rfc") if e: event_revisions.append(dict(id=e.id, time=e.time, rev="RFC")) event_revisions.sort(key=lambda x: (x["time"], x["id"]))