Skip to content

Commit

Permalink
Reduce the number of DB queries when retrieving translation history (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
mathjazz authored Oct 10, 2024
1 parent 0848c24 commit d619331
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pontoon/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from django.contrib.auth.models import User
from django.core.paginator import EmptyPage, Paginator
from django.db import transaction
from django.db.models import Q
from django.db.models import Prefetch, Q
from django.http import (
Http404,
HttpResponse,
Expand Down Expand Up @@ -403,7 +403,17 @@ def get_translation_history(request):
translations = Translation.objects.filter(
entity=entity,
locale=locale,
).prefetch_related("comments")
).prefetch_related(
Prefetch(
"comments",
queryset=Comment.objects.prefetch_related("author").order_by("timestamp"),
),
"user",
"approved_user",
"rejected_user",
"errors",
"warnings",
)

if plural_form != -1:
translations = translations.filter(plural_form=plural_form)
Expand All @@ -425,7 +435,7 @@ def get_translation_history(request):
"approved_date": t.approved_date,
"rejected_user": User.display_name_or_blank(t.rejected_user),
"rejected_date": t.rejected_date,
"comments": [c.serialize() for c in t.comments.order_by("timestamp")],
"comments": [c.serialize() for c in t.comments.all()],
"machinery_sources": t.machinery_sources_values,
}
)
Expand Down

0 comments on commit d619331

Please sign in to comment.