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

Optimize query for supervision events

parent ebd5e7f4
No related branches found
No related tags found
1 merge request!384Optimize query for supervision events
Pipeline #193597 passed
...@@ -505,7 +505,7 @@ class SupervisionEvent(LessonEvent): ...@@ -505,7 +505,7 @@ class SupervisionEvent(LessonEvent):
cls, request: HttpRequest | None = None, params: dict[str, any] | None = None, **kwargs cls, request: HttpRequest | None = None, params: dict[str, any] | None = None, **kwargs
) -> Iterable: ) -> Iterable:
"""Return all objects that should be included in the calendar.""" """Return all objects that should be included in the calendar."""
objs = super().get_objects(request, params, no_effect=True, **kwargs) q = Q()
if params: if params:
obj_id = int(params.get("id", 0)) obj_id = int(params.get("id", 0))
type_ = params.get("type", None) type_ = params.get("type", None)
...@@ -514,21 +514,30 @@ class SupervisionEvent(LessonEvent): ...@@ -514,21 +514,30 @@ class SupervisionEvent(LessonEvent):
amending = params.get("amending", False) amending = params.get("amending", False)
if not_amended: if not_amended:
objs = objs.not_amended() q = q & SupervisionEventQuerySet.not_amended_q()
if not_amending: if not_amending:
objs = objs.not_amending() q = q & SupervisionEventQuerySet.not_amending_q()
if amending: if amending:
objs = objs.amending() q = q & SupervisionEventQuerySet.amending_q()
if type_ and obj_id: if type_ and obj_id:
if type_ == "TEACHER": if type_ == "TEACHER":
return objs.for_teacher(obj_id) q = q & SupervisionEventQuerySet.for_teacher_q(obj_id)
elif type_ == "GROUP": elif type_ == "GROUP":
return objs.for_group(obj_id) q = q & SupervisionEventQuerySet.for_group_q(obj_id)
elif type_ == "ROOM": elif type_ == "ROOM":
return objs.for_room(obj_id) q = q & SupervisionEventQuerySet.for_room_q(obj_id)
if request: elif request:
return objs.for_person(request.user.person) q = q & SupervisionEventQuerySet.for_person_q(request.user.person)
return objs
return super().get_objects(
request,
params,
no_effect=True,
additional_filter=q,
select_related=["subject"],
prefetch_related=["teachers", "rooms"],
**kwargs,
)
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