Skip to content

Commit

Permalink
Attempted to speed up problems list.
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLovesDoggo committed Apr 6, 2024
1 parent 9937701 commit 8c530f2
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions gameserver/views/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,29 @@


def int_list(l):
if not l:
return None
return list(map(int, filter(lambda x: x.isnumeric(), l)))


class ProblemList(ListView, mixin.MetaMixin):
template_name = "problem/list.html"
context_object_name = "problems"
paginate_by = 50
paginate_by = 35
title = "Practice Problems"

def get_queryset(self):
base = models.Problem.get_visible_problems(self.request.user).prefetch_related(
"problem_type", "problem_group"
)

if self.selected_types is not None:
base = base.filter(problem_type__in=self.selected_types)
if self.selected_groups is not None and not self.request.in_contest:
base = base.filter(problem_group__in=self.selected_groups)

q = (
models.Problem.get_visible_problems(self.request.user)
.prefetch_related("problem_type", "problem_group")
.filter(
Q(problem_type__in=self.selected_types) if len(self.selected_types) else Q(),
(
Q(problem_group__in=self.selected_groups)
if len(self.selected_groups) and not self.request.in_contest
else Q()
),
)
.distinct()
base.distinct()
.order_by("points", "name")
)
if self.hide_solved and self.request.user.is_authenticated:
Expand Down

0 comments on commit 8c530f2

Please sign in to comment.