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

Add prefetch option for get_el_by_pk

parent 213fa8fd
No related branches found
No related tags found
1 merge request!83Minimize query count
This commit is part of merge request !83. Comments created here will be created in the context of that merge request.
......@@ -16,9 +16,15 @@ def get_el_by_pk(
year: Optional[int] = None,
week: Optional[int] = None,
regular: Optional[str] = None,
prefetch: bool = False,
):
if type_ == TimetableType.GROUP.value:
return get_object_or_404(Group, pk=pk)
return get_object_or_404(
Group.objects.prefetch_related("owners", "parent_groups")
if prefetch
else Group,
pk=pk,
)
elif type_ == TimetableType.TEACHER.value:
return get_object_or_404(Person, pk=pk)
elif type_ == TimetableType.ROOM.value:
......
......@@ -116,7 +116,7 @@ def timetable(
is_smart = regular != "regular"
el = get_el_by_pk(request, type_, pk)
el = get_el_by_pk(request, type_, pk, prefetch=True)
if type(el) == HttpResponseNotFound:
return HttpResponseNotFound()
......
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