diff --git a/api/launchpad/serializers.py b/api/launchpad/serializers.py index 146ead6c..1714d1e0 100644 --- a/api/launchpad/serializers.py +++ b/api/launchpad/serializers.py @@ -6,6 +6,7 @@ from db.user import User from db.organization import UserOrganizationLink from db.task import KarmaActivityLog +import json class LaunchpadLeaderBoardSerializer(serializers.ModelSerializer): rank = serializers.SerializerMethodField() @@ -50,12 +51,14 @@ def get_rank(self, obj): ).annotate( karma=Subquery(total_karma_subquery, output_field=IntegerField()), time_=Max("karma_activity_log_user__created_at"), - ).order_by("-karma", "time_").annotate( - rank=Window( - expression=Rank(), - order_by=[F("karma").desc(), F("time_").asc()] - ) - ) - - return users.get(id=obj.id).rank + ).order_by("-karma", "time_") + + # high complexity + rank = 0 + for data in users: + rank += 1 + if data.id == obj.id: + break + + return rank