Skip to content

Commit

Permalink
Merge pull request #646 from City-of-Helsinki/link-1396-optimize-related
Browse files Browse the repository at this point in the history
Optimize related for event?include
  • Loading branch information
voneiden authored Aug 1, 2023
2 parents 46ee38c + a10543a commit b7b5e58
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions events/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3248,14 +3248,15 @@ class EventViewSet(
Event.objects.all()
.select_related("location", "publisher")
.prefetch_related(
"offers",
"keywords",
"audience",
"external_links",
"keywords",
"images",
"images__publisher",
"external_links",
"sub_events",
"in_language",
"offers",
"registration",
"sub_events",
"videos",
)
)
Expand Down Expand Up @@ -3311,14 +3312,19 @@ def get_queryset(self):
if "include" in context:
for included in context["include"]:
if included == "location":
queryset = queryset.prefetch_related(
queryset = queryset.select_related(
"location__publisher"
).prefetch_related(
"location__divisions",
"location__divisions__type",
"location__divisions__municipality",
)
if included == "keywords":
queryset = queryset.prefetch_related(
"keywords__alt_labels", "audience__alt_labels"
"audience__alt_labels",
"audience__publisher",
"keywords__alt_labels",
"keywords__publisher",
)
return apply_select_and_prefetch(
queryset=queryset, extensions=get_extensions_from_request(self.request)
Expand Down

0 comments on commit b7b5e58

Please sign in to comment.