Skip to content

Commit

Permalink
Merge pull request #1817 from gtech-mulearn/dev-server
Browse files Browse the repository at this point in the history
org query time fix
  • Loading branch information
adnankattekaden authored Dec 13, 2023
2 parents 9fc46f4 + 5ed78b2 commit 157629c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 33 deletions.
59 changes: 26 additions & 33 deletions api/common/common_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,43 +279,37 @@ class CollegeWiseLcReport(APIView):
def get(self, request):
date = request.query_params.get('date')
if date:
learning_circle_count_subquery = (
lc_query = (
LearningCircle.objects.filter(org__org_type=OrganizationType.COLLEGE.value, created_at__date=date)
.values(org_title=F("org__title"))
.annotate(learning_circle_count=Count("id"))
.filter(org_title=OuterRef("org_title"))
.values("learning_circle_count")
[:1]
)

learning_circles_info = (
LearningCircle.objects.filter(org__org_type=OrganizationType.COLLEGE.value, created_at__date=date)
.values(org_title=F("org__title"))
.annotate(
learning_circle_count=Subquery(learning_circle_count_subquery),
user_count=Count("user_circle_link_circle__user")
)
.order_by("org_title")
.select_related("org")
.prefetch_related("user_circle_link_circle__user")
)
learning_circle_count_subquery = (lc_query.values(org_title=F("org__title"))
.annotate(learning_circle_count=Count("id"))
.filter(org_title=OuterRef("org_title"))
.values("learning_circle_count")
[:1])
learning_circles_info = (lc_query.values(org_title=F("org__title"))
.annotate(
learning_circle_count=Subquery(learning_circle_count_subquery),
user_count=Count("user_circle_link_circle__user"),
).order_by("org_title"))
else:
learning_circle_count_subquery = (
lc_query = (
LearningCircle.objects.filter(org__org_type=OrganizationType.COLLEGE.value)
.values(org_title=F("org__title"))
.annotate(learning_circle_count=Count("id"))
.filter(org_title=OuterRef("org_title"))
.values("learning_circle_count")
[:1]
)

learning_circles_info = (
LearningCircle.objects.filter(org__org_type=OrganizationType.COLLEGE.value)
.values(org_title=F("org__title"))
.annotate(
learning_circle_count=Subquery(learning_circle_count_subquery),
user_count=Count("user_circle_link_circle__user"),
)
.order_by("org_title")
.select_related("org")
.prefetch_related("user_circle_link_circle__user")
)
learning_circle_count_subquery = (lc_query.values(org_title=F("org__title"))
.annotate(learning_circle_count=Count("id"))
.filter(org_title=OuterRef("org_title"))
.values("learning_circle_count")
[:1])
learning_circles_info = (lc_query.values(org_title=F("org__title"))
.annotate(
learning_circle_count=Subquery(learning_circle_count_subquery),
user_count=Count("user_circle_link_circle__user"),
).order_by("org_title"))

paginated_queryset = CommonUtils.get_paginated_queryset(
learning_circles_info,
Expand Down Expand Up @@ -379,7 +373,6 @@ def get(self, request):
district=F("user__user_organization_link_user__org__district__name"),
circle_ig=F("circle__ig__name"),
organisation=F("user__user_organization_link_user__org__title"),

)
.annotate(
karma_earned=Sum(
Expand Down
2 changes: 2 additions & 0 deletions api/common/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
path('lc-report/csv/', common_views.LcReportDownloadAPI.as_view()),
path('lc-enrollment/', common_views.LearningCircleEnrollment.as_view()),
path('lc-enrollment/csv/', common_views.LearningCircleEnrollmentCSV.as_view()),

path('global-count/', common_views.GlobalCountAPI.as_view()),

path('gta-sandshore/', common_views.GTASANDSHOREAPI.as_view()),
path('profile-pic/<str:muid>/', common_views.UserProfilePicAPI.as_view()),
path('list-ig/', common_views.ListIGAPI.as_view()),
Expand Down

0 comments on commit 157629c

Please sign in to comment.