dnscms: prefetch and select related when quering future events
This commit is contained in:
+18
-2
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user