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

Prefetch personal notes to avoid additional queries

parent 324fad70
No related branches found
No related tags found
1 merge request!429Resolve "Adapt to active school term"
......@@ -154,7 +154,9 @@ class Documentation(CalendarEvent):
datetime_end__gte=datetime_start,
amends__in=[e["REFERENCE_OBJECT"] for e in events],
)
.prefetch_related("participations", "teachers")
.prefetch_related(
"participations", "teachers", "personal_notes", "personal_notes__extra_mark"
)
.select_related("course", "subject")
)
......
......@@ -117,6 +117,11 @@ class DocumentationType(PermissionsTypeMixin, DjangoFilterMixin, DjangoObjectTyp
p for p in root.participations.all() if p.person == info.context.user.person
]
return []
# Annotate participations with prefetched documentation data for personal notes
for participation in root.participations.all():
participation._prefetched_documentation = root
return root.participations.all()
......
......@@ -41,6 +41,12 @@ class ParticipationStatusType(
@staticmethod
def resolve_notes_with_extra_mark(root: ParticipationStatus, info, **kwargs):
if hasattr(root, "_prefetched_documentation"):
return [
p
for p in root._prefetched_documentation.personal_notes.all()
if p.person_id == root.person_id and p.extra_mark
]
return NewPersonalNote.objects.filter(
person=root.person,
documentation=root.related_documentation,
......@@ -49,6 +55,12 @@ class ParticipationStatusType(
@staticmethod
def resolve_notes_with_note(root: ParticipationStatus, info, **kwargs):
if hasattr(root, "_prefetched_documentation"):
return [
p
for p in root._prefetched_documentation.personal_notes.all()
if p.person_id == root.person_id and p.note
]
return NewPersonalNote.objects.filter(
person=root.person,
documentation=root.related_documentation,
......
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