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:
parent
6e99c007a5
commit
3036014ea2
7 changed files with 49 additions and 6 deletions
|
|
@ -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"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue