diff --git a/api/launchpad/launchpad_views.py b/api/launchpad/launchpad_views.py index a2bb72cb..270fec6f 100644 --- a/api/launchpad/launchpad_views.py +++ b/api/launchpad/launchpad_views.py @@ -1,16 +1,4 @@ -from django.db.models import ( - Sum, - Max, - Prefetch, - When, - Case, - IntegerField, - CharField, - F, - OuterRef, - Subquery, -) -from django.db.models.functions import Coalesce +from django.db.models import Q, Sum, Max from rest_framework.views import APIView @@ -18,21 +6,10 @@ from utils.response import CustomResponse from utils.utils import CommonUtils from db.user import User -from db.organization import Organization, District, State -from db.task import KarmaActivityLog class Leaderboard(APIView): def get(self, request): - karma_subquery = ( - KarmaActivityLog.objects.filter( - user=OuterRef("id"), - task__event="launchpad", - appraiser_approved=True, - ) - .annotate(total_karma=Sum("karma")) - .values("total_karma") - ) users = ( User.objects.filter( karma_activity_log_user__task__event="launchpad", @@ -40,7 +17,13 @@ def get(self, request): karma_activity_log_user__task__hashtag="#lp24-introduction", ) .annotate( - karma=Subquery(karma_subquery, output_field=IntegerField()), + karma=Sum( + "karma_activity_log_user__karma", + filter=Q( + karma_activity_log_user__task__event="launchpad", + karma_activity_log_user__appraiser_approved=True, + ), + ), time_=Max("karma_activity_log_user__created_at"), ) .order_by("-karma", "time_")