Skip to content
Snippets Groups Projects
Verified Commit abadf508 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Further optimize queries

parent f99e4518
No related branches found
No related tags found
1 merge request!429Resolve "Adapt to active school term"
Pipeline #193905 failed
......@@ -155,7 +155,12 @@ class Documentation(CalendarEvent):
amends__in=[e["REFERENCE_OBJECT"] for e in events],
)
.prefetch_related(
"participations", "teachers", "personal_notes", "personal_notes__extra_mark"
"participations",
"participations__person",
"participations__absence_reason",
"teachers",
"personal_notes",
"personal_notes__extra_mark",
)
.select_related("course", "subject")
)
......
from django.core.exceptions import PermissionDenied
import graphene
from graphene_django import bypass_get_queryset
from graphene_django.types import DjangoObjectType
from reversion import create_revision, set_comment, set_user
......@@ -61,12 +62,14 @@ class DocumentationType(PermissionsTypeMixin, DjangoFilterMixin, DjangoObjectTyp
old_id = graphene.ID(required=False)
@staticmethod
@bypass_get_queryset
def resolve_amends(root: Documentation, info, **kwargs):
if hasattr(root, "_amends_prefetched"):
return root._amends_prefetched
return root.amends
@staticmethod
@bypass_get_queryset
def resolve_teachers(root: Documentation, info, **kwargs):
if not str(root.pk).startswith("DUMMY") and hasattr(root, "teachers"):
return root.teachers
......@@ -105,6 +108,7 @@ class DocumentationType(PermissionsTypeMixin, DjangoFilterMixin, DjangoObjectTyp
)
@staticmethod
@bypass_get_queryset
def resolve_participations(root: Documentation, info, **kwargs):
# A dummy documentation will not have any participations
if str(root.pk).startswith("DUMMY") or not hasattr(root, "participations"):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment