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

Prefetch object permissions in my_students

parent 7f35a683
No related branches found
No related tags found
1 merge request!173Optimize ORM workload for week view by avoiding/minimizing prefetch operations
Pipeline #7322 failed
...@@ -711,12 +711,26 @@ def my_students(request: HttpRequest) -> HttpResponse: ...@@ -711,12 +711,26 @@ def my_students(request: HttpRequest) -> HttpResponse:
.distinct() .distinct()
) )
# Prefetch object permissions for persons and groups the persons are members of
# because the object permissions are checked for both persons and groups
all_persons = Person.objects.filter(member_of__in=relevant_groups)
checker = ObjectPermissionChecker(request.user)
checker.prefetch_perms(relevant_groups)
checker.prefetch_perms(all_persons)
new_groups = [] new_groups = []
for group in relevant_groups: for group in relevant_groups:
persons = group.generate_person_list_with_class_register_statistics( persons = group.generate_person_list_with_class_register_statistics(
group.members.prefetch_related("primary_group__owners") group.members.prefetch_related(
"primary_group__owners",
Prefetch("member_of", queryset=relevant_groups, to_attr="member_of_prefetched"),
)
) )
new_groups.append((group, persons)) persons_for_group = []
for person in persons:
person.set_object_permission_checker(checker)
persons_for_group.append(person)
new_groups.append((group, persons_for_group))
context["groups"] = new_groups context["groups"] = new_groups
context["excuse_types"] = ExcuseType.objects.all() context["excuse_types"] = ExcuseType.objects.all()
......
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