refactor: add annotations in queryset to return sub_issues_count and total members in workspace (#185)

* refactor: add anotations in queryset to return sub_issues_count

* refactor: add sub issue count in modules cycles and my issues endpoint
This commit is contained in:
pablohashescobar 2023-01-26 11:41:11 +05:30 committed by GitHub
parent 6e99c007a5
commit 3036014ea2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 49 additions and 6 deletions

View file

@ -1,6 +1,6 @@
# Django Imports
from django.db import IntegrityError
from django.db.models import Prefetch
from django.db.models import Prefetch, F, OuterRef, Func
# Third party imports
from rest_framework.response import Response
@ -118,6 +118,12 @@ class ModuleIssueViewSet(BaseViewSet):
return self.filter_queryset(
super()
.get_queryset()
.annotate(
sub_issues_count=Issue.objects.filter(parent=OuterRef("issue"))
.order_by()
.annotate(count=Func(F("id"), function="Count"))
.values("count")
)
.filter(workspace__slug=self.kwargs.get("slug"))
.filter(project_id=self.kwargs.get("project_id"))
.filter(module_id=self.kwargs.get("module_id"))