From 03455fca2cf721be9cc00bd5a51529e199f9e32b Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Fri, 27 Jan 2023 17:58:44 -0600 Subject: [PATCH] Optimize a query --- judge/views/problem.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/judge/views/problem.py b/judge/views/problem.py index 4fadf70..904d86b 100644 --- a/judge/views/problem.py +++ b/judge/views/problem.py @@ -588,11 +588,8 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView queryset = Problem.get_visible_problems(self.request.user) queryset = queryset.select_related("group") if self.profile is not None and self.hide_solved: - queryset = queryset.exclude( - id__in=Submission.objects.filter( - user=self.profile, points=F("problem__points") - ).values_list("problem__id", flat=True) - ) + solved_problems = self.get_completed_problems() + queryset = queryset.exclude(id__in=solved_problems) if not self.org_query and self.request.organization: self.org_query = [self.request.organization.id] if self.org_query: