Skip to content

Commit

Permalink
remove duplicated qwuery
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLovesDoggo committed Mar 9, 2024
1 parent daa0659 commit 4f97111
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions gameserver/models/contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,10 @@ def participant(self):

def _get_unique_correct_submissions(self):
# Switch to ContestProblem -> Problem Later
return (
self.submissions.filter(submission__is_correct=True)
.values("submission__problem", "problem__points")
.distinct()
)

return (self.submissions.filter(submission__is_correct=True)
.select_related('problem')
.values('problem','problem__points').distinct())

def points(self):
points = self._get_unique_correct_submissions().aggregate(
points=Coalesce(Sum("problem__points"), 0)
Expand Down Expand Up @@ -382,6 +380,7 @@ class ContestSubmission(models.Model):
on_delete=models.CASCADE,
related_name="submissions",
related_query_name="submission",
db_index=True,
)
problem = models.ForeignKey(
ContestProblem,
Expand All @@ -390,7 +389,8 @@ class ContestSubmission(models.Model):
related_query_name="submission",
)
submission = models.OneToOneField(
"Submission", on_delete=models.CASCADE, related_name="contest_submission"
"Submission", on_delete=models.CASCADE, related_name="contest_submission",
db_index=True,
)

def __str__(self):
Expand Down

0 comments on commit 4f97111

Please sign in to comment.