Skip to content

Commit

Permalink
Use MembershipScore.performance_total for sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
Syriiin committed Jun 2, 2024
1 parent 3bce099 commit 9e5799f
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions leaderboards/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from django.db.models import Max, Q

from common.osu.enums import Gamemode
from common.osu.utils import calculate_pp_total
from leaderboards.enums import LeaderboardAccessType
from profiles.enums import ScoreResult, ScoreSet
from profiles.models import OsuUser, Score, ScoreFilter


Expand Down Expand Up @@ -81,21 +79,18 @@ class Leaderboard(models.Model):
)()

def get_pp_record(self) -> typing.Union[Score, None]:
scores = Score.objects.non_restricted().filter(
membership__leaderboard_id=self.id
)

scores = scores.annotate_sorting_pp(self.score_set)
scores = self.get_top_scores()

return scores.aggregate(Max("sorting_pp"))["sorting_pp__max"]
return scores.aggregate(Max("membership_scores__performance_total"))[
"membership_scores__performance_total__max"
]

def get_top_scores(self, limit=5):
scores = (
Score.objects.non_restricted()
.distinct()
.filter(membership__leaderboard_id=self.id)
.order_by("-membership_scores__performance_total", "date")
.select_related("user_stats", "user_stats__user", "beatmap")
.get_score_set(score_set=self.score_set)
)

return scores[:limit]
Expand Down

0 comments on commit 9e5799f

Please sign in to comment.