Refactor exam list annotation to use unfiltered counts for accurate overview matching

This commit is contained in:
Ross
2026-01-04 12:50:47 +00:00
parent c3a70b079d
commit 3e691d774c
+4 -3
View File
@@ -1922,10 +1922,11 @@ class ExamViews(View, LoginRequiredMixin):
.order_by("name")
)
# Annotate counts for template usage so `.count()` is not called per-object
# Annotate counts for template usage so `.count()` is not called per-object.
# Use unfiltered counts to match the per-exam `exam_overview` counts.
exam_list = exam_list.annotate(
valid_cid_users_count=Count("valid_cid_users", filter=Q(valid_cid_users__active=True)),
valid_user_users_count=Count("valid_user_users", filter=Q(valid_user_users__is_active=True)),
valid_cid_users_count=Count("valid_cid_users"),
valid_user_users_count=Count("valid_user_users"),
).select_related("examcollection").prefetch_related("author")
if not all: