Skip to content

Commit

Permalink
fix: optimize queries for DocumentChangesFeed (#5675)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjsparks authored May 23, 2023
1 parent 40765d8 commit 6178519
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ietf/doc/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def subtitle(self, obj):
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

Expand Down
12 changes: 10 additions & 2 deletions ietf/doc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

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
Expand Down Expand Up @@ -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"]))
Expand Down

3 comments on commit 6178519

@ZZZ5419

This comment was marked as spam.

@ZZZ5419

This comment was marked as spam.

@ZZZ5419

This comment was marked as spam.

Please sign in to comment.