feat: attachment and link count in issues list (#777)

This commit is contained in:
pablohashescobar 2023-04-11 18:47:36 +05:30 committed by GitHub
parent ce26bed44a
commit 6279a04267
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 0 deletions

View File

@ -522,6 +522,8 @@ class IssueLiteSerializer(BaseSerializer):
sub_issues_count = serializers.IntegerField(read_only=True) sub_issues_count = serializers.IntegerField(read_only=True)
cycle_id = serializers.UUIDField(read_only=True) cycle_id = serializers.UUIDField(read_only=True)
module_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: class Meta:
model = Issue model = Issue

View File

@ -28,6 +28,8 @@ from plane.db.models import (
CycleIssue, CycleIssue,
Issue, Issue,
CycleFavorite, CycleFavorite,
IssueLink,
IssueAttachment,
) )
from plane.bgtasks.issue_activites_task import issue_activity from plane.bgtasks.issue_activites_task import issue_activity
from plane.utils.grouper import group_results from plane.utils.grouper import group_results
@ -226,6 +228,20 @@ class CycleIssueViewSet(BaseViewSet):
.prefetch_related("labels") .prefetch_related("labels")
.order_by(order_by) .order_by(order_by)
.filter(**filters) .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 issues_data = IssueStateSerializer(issues, many=True).data

View File

@ -148,6 +148,20 @@ class IssueViewSet(BaseViewSet):
.filter(**filters) .filter(**filters)
.annotate(cycle_id=F("issue_cycle__id")) .annotate(cycle_id=F("issue_cycle__id"))
.annotate(module_id=F("issue_module__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 = ( issue_queryset = (

View File

@ -31,6 +31,8 @@ from plane.db.models import (
Issue, Issue,
ModuleLink, ModuleLink,
ModuleFavorite, ModuleFavorite,
IssueLink,
IssueAttachment,
) )
from plane.bgtasks.issue_activites_task import issue_activity from plane.bgtasks.issue_activites_task import issue_activity
from plane.utils.grouper import group_results from plane.utils.grouper import group_results
@ -204,6 +206,20 @@ class ModuleIssueViewSet(BaseViewSet):
.prefetch_related("labels") .prefetch_related("labels")
.order_by(order_by) .order_by(order_by)
.filter(**filters) .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 issues_data = IssueStateSerializer(issues, many=True).data