Skip to content

Commit

Permalink
Expiermental optimizations (see origin/optimze2)
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Lee <contact@paullee.dev>
  • Loading branch information
JasonLovesDoggo and HillcrestEnigma committed Apr 2, 2024
1 parent ee20ed5 commit 61de749
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
11 changes: 7 additions & 4 deletions gameserver/views/contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ def get_title(self):
return "Problems for " + self.object.name

def get_queryset(self):
return self.object.problems.select_related("problem")
return self.object.problems.only(
"problem", "problem__problem_type", "points"
).select_related("problem")


class ContestSubmissionList(ContestDetailsMixin, ListView, mixin.MetaMixin):
Expand All @@ -183,8 +185,9 @@ class ContestSubmissionList(ContestDetailsMixin, ListView, mixin.MetaMixin):
def get_queryset(self):
return (
models.ContestSubmission.objects.filter(participation__contest=self.object)
.select_related("problem", "participation")
.order_by("-pk")
.only("pk", "problem", "participation")
.select_related("problem", "participation")
)


Expand All @@ -205,7 +208,7 @@ def get_queryset(self):
]
):
ContestScore.reset_data(contest=self.object)
return ContestScore.ranks(contest=self.object)
return ContestScore.ranks(contest=self.object).only("team").select_related("team")

def _get_contest(self, slug):
return get_object_or_404(models.Contest, slug=slug)
Expand Down Expand Up @@ -237,7 +240,7 @@ def get_title(self):
def get_queryset(self):
return ContestScore.ranks(
self.contest, self.contest.participations.filter(participants__organizations=self.org)
).select_related("participation__team")
).only("team").select_related("team")
# return self.contest._ranks(
# self.contest.participations.filter(participants__organizations=self.org),
# ).select_related("team")
Expand Down
1 change: 1 addition & 0 deletions gameserver/views/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class SubmissionList(ListView, mixin.MetaMixin):
def get_queryset(self):
return (
models.Submission.get_visible_submissions(self.request.user)
.only("pk", "is_correct", "problem", "user", "date_created")
.select_related("user", "problem")
.order_by("-pk")
)
Expand Down
4 changes: 2 additions & 2 deletions gameserver/views/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class TeamList(ListView, mixin.MetaMixin):
paginate_by = 50
title = "Teams"

def get_ordering(self):
return "name"
def get_queryset(self):
return models.Team.objects.only("pk", "name").prefetch_related("members")


class TeamDetail(
Expand Down
3 changes: 2 additions & 1 deletion gameserver/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def get_queryset(self):
return (
models.Submission.get_visible_submissions(self.request.user)
.filter(user=self.object)
.select_related("problem")
.only("pk", "is_correct", "problem", "user", "date_created")
.select_related("user", "problem")
.order_by("-pk")
)

Expand Down

0 comments on commit 61de749

Please sign in to comment.