dnscms: prefetch and select related when quering future events

This commit is contained in:
2026-05-19 23:46:13 +02:00
parent 154338057d
commit 80b9cdbc33
2 changed files with 78 additions and 2 deletions
+18 -2
View File
@@ -1,7 +1,7 @@
from django import forms
from django.core.exceptions import ValidationError
from django.db import models
from django.db.models import Min, Q, UniqueConstraint
from django.db.models import Min, Prefetch, Q, UniqueConstraint
from django.utils import timezone
from django.utils.html import mark_safe
from django.utils.translation import gettext_lazy as _
@@ -45,7 +45,23 @@ class EventIndex(HeadlessMixin, Page):
subpage_types = ["events.EventPage"]
def future_events(self, info, **kwargs):
return EventPage.objects.live().future().order_by("next_occurrence")
return (
EventPage.objects.live()
.future()
.order_by("next_occurrence")
.select_related("featured_image")
.prefetch_related(
Prefetch(
"occurrences",
queryset=EventOccurrence.objects.select_related("venue"),
),
"categories",
Prefetch(
"organizers",
queryset=EventOrganizer.objects.select_related("association"),
),
)
)
graphql_fields = [
GraphQLCollection(