From 6279a042675efc649d971065322bc1983e67222d Mon Sep 17 00:00:00 2001 From: pablohashescobar <118773738+pablohashescobar@users.noreply.github.com> Date: Tue, 11 Apr 2023 18:47:36 +0530 Subject: [PATCH] feat: attachment and link count in issues list (#777) --- apiserver/plane/api/serializers/issue.py | 2 ++ apiserver/plane/api/views/cycle.py | 16 ++++++++++++++++ apiserver/plane/api/views/issue.py | 14 ++++++++++++++ apiserver/plane/api/views/module.py | 16 ++++++++++++++++ 4 files changed, 48 insertions(+) diff --git a/apiserver/plane/api/serializers/issue.py b/apiserver/plane/api/serializers/issue.py index e2cc42b80..d197fb843 100644 --- a/apiserver/plane/api/serializers/issue.py +++ b/apiserver/plane/api/serializers/issue.py @@ -522,6 +522,8 @@ class IssueLiteSerializer(BaseSerializer): sub_issues_count = serializers.IntegerField(read_only=True) cycle_id = serializers.UUIDField(read_only=True) module_id = serializers.UUIDField(read_only=True) + attachment_count = serializers.IntegerField(read_only=True) + link_count = serializers.IntegerField(read_only=True) class Meta: model = Issue diff --git a/apiserver/plane/api/views/cycle.py b/apiserver/plane/api/views/cycle.py index 694eea02f..df95a1b7a 100644 --- a/apiserver/plane/api/views/cycle.py +++ b/apiserver/plane/api/views/cycle.py @@ -28,6 +28,8 @@ from plane.db.models import ( CycleIssue, Issue, CycleFavorite, + IssueLink, + IssueAttachment, ) from plane.bgtasks.issue_activites_task import issue_activity from plane.utils.grouper import group_results @@ -226,6 +228,20 @@ class CycleIssueViewSet(BaseViewSet): .prefetch_related("labels") .order_by(order_by) .filter(**filters) + .annotate( + link_count=IssueLink.objects.filter(issue=OuterRef("id")) + .order_by() + .annotate(count=Func(F("id"), function="Count")) + .values("count") + ) + .annotate( + attachment_count=IssueAttachment.objects.filter( + issue=OuterRef("id") + ) + .order_by() + .annotate(count=Func(F("id"), function="Count")) + .values("count") + ) ) issues_data = IssueStateSerializer(issues, many=True).data diff --git a/apiserver/plane/api/views/issue.py b/apiserver/plane/api/views/issue.py index f743ad4f0..a3098c381 100644 --- a/apiserver/plane/api/views/issue.py +++ b/apiserver/plane/api/views/issue.py @@ -148,6 +148,20 @@ class IssueViewSet(BaseViewSet): .filter(**filters) .annotate(cycle_id=F("issue_cycle__id")) .annotate(module_id=F("issue_module__id")) + .annotate( + link_count=IssueLink.objects.filter(issue=OuterRef("id")) + .order_by() + .annotate(count=Func(F("id"), function="Count")) + .values("count") + ) + .annotate( + attachment_count=IssueAttachment.objects.filter( + issue=OuterRef("id") + ) + .order_by() + .annotate(count=Func(F("id"), function="Count")) + .values("count") + ) ) issue_queryset = ( diff --git a/apiserver/plane/api/views/module.py b/apiserver/plane/api/views/module.py index ec393f47a..0abf47c8b 100644 --- a/apiserver/plane/api/views/module.py +++ b/apiserver/plane/api/views/module.py @@ -31,6 +31,8 @@ from plane.db.models import ( Issue, ModuleLink, ModuleFavorite, + IssueLink, + IssueAttachment, ) from plane.bgtasks.issue_activites_task import issue_activity from plane.utils.grouper import group_results @@ -204,6 +206,20 @@ class ModuleIssueViewSet(BaseViewSet): .prefetch_related("labels") .order_by(order_by) .filter(**filters) + .annotate( + link_count=IssueLink.objects.filter(issue=OuterRef("id")) + .order_by() + .annotate(count=Func(F("id"), function="Count")) + .values("count") + ) + .annotate( + attachment_count=IssueAttachment.objects.filter( + issue=OuterRef("id") + ) + .order_by() + .annotate(count=Func(F("id"), function="Count")) + .values("count") + ) ) issues_data = IssueStateSerializer(issues, many=True).data