forked from github/plane
feat: estimate points data in cycles list endpoint (#1015)
* feat: estimate points data in cycles list endpoint * dev: prefetch for assignees * dev: update sum for estimate points
This commit is contained in:
parent
083562b24c
commit
fb165d080e
@ -19,7 +19,10 @@ class CycleSerializer(BaseSerializer):
|
|||||||
started_issues = serializers.IntegerField(read_only=True)
|
started_issues = serializers.IntegerField(read_only=True)
|
||||||
unstarted_issues = serializers.IntegerField(read_only=True)
|
unstarted_issues = serializers.IntegerField(read_only=True)
|
||||||
backlog_issues = serializers.IntegerField(read_only=True)
|
backlog_issues = serializers.IntegerField(read_only=True)
|
||||||
assignees = serializers.SerializerMethodField()
|
assignees = serializers.SerializerMethodField(read_only=True)
|
||||||
|
total_estimates = serializers.IntegerField(read_only=True)
|
||||||
|
completed_estimates = serializers.IntegerField(read_only=True)
|
||||||
|
started_estimates = serializers.IntegerField(read_only=True)
|
||||||
|
|
||||||
workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace")
|
workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace")
|
||||||
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||||
|
@ -3,7 +3,7 @@ import json
|
|||||||
|
|
||||||
# Django imports
|
# Django imports
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
from django.db.models import OuterRef, Func, F, Q, Exists, OuterRef, Count, Prefetch
|
from django.db.models import OuterRef, Func, F, Q, Exists, OuterRef, Count, Prefetch, Sum
|
||||||
from django.core import serializers
|
from django.core import serializers
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
@ -24,13 +24,13 @@ from plane.api.serializers import (
|
|||||||
)
|
)
|
||||||
from plane.api.permissions import ProjectEntityPermission
|
from plane.api.permissions import ProjectEntityPermission
|
||||||
from plane.db.models import (
|
from plane.db.models import (
|
||||||
|
User,
|
||||||
Cycle,
|
Cycle,
|
||||||
CycleIssue,
|
CycleIssue,
|
||||||
Issue,
|
Issue,
|
||||||
CycleFavorite,
|
CycleFavorite,
|
||||||
IssueLink,
|
IssueLink,
|
||||||
IssueAttachment,
|
IssueAttachment,
|
||||||
User,
|
|
||||||
)
|
)
|
||||||
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
|
||||||
@ -119,6 +119,25 @@ class CycleViewSet(BaseViewSet):
|
|||||||
filter=Q(issue_cycle__issue__state__group="backlog"),
|
filter=Q(issue_cycle__issue__state__group="backlog"),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
.annotate(total_estimates=Sum("issue_cycle__issue__estimate_point"))
|
||||||
|
.annotate(
|
||||||
|
completed_estimates=Sum(
|
||||||
|
"issue_cycle__issue__estimate_point",
|
||||||
|
filter=Q(issue_cycle__issue__state__group="completed"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.annotate(
|
||||||
|
started_estimates=Sum(
|
||||||
|
"issue_cycle__issue__estimate_point",
|
||||||
|
filter=Q(issue_cycle__issue__state__group="started"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.prefetch_related(
|
||||||
|
Prefetch(
|
||||||
|
"issue_cycle__issue__assignees",
|
||||||
|
queryset=User.objects.only("avatar", "first_name", "id").distinct(),
|
||||||
|
)
|
||||||
|
)
|
||||||
.order_by("-is_favorite", "name")
|
.order_by("-is_favorite", "name")
|
||||||
.distinct()
|
.distinct()
|
||||||
)
|
)
|
||||||
@ -414,11 +433,10 @@ class CycleDateCheckEndpoint(BaseAPIView):
|
|||||||
try:
|
try:
|
||||||
start_date = request.data.get("start_date", False)
|
start_date = request.data.get("start_date", False)
|
||||||
end_date = request.data.get("end_date", False)
|
end_date = request.data.get("end_date", False)
|
||||||
cycle_id = request.data.get("cycle_id", False)
|
|
||||||
|
|
||||||
if not start_date or not end_date:
|
if not start_date or not end_date:
|
||||||
return Response(
|
return Response(
|
||||||
{"error": "Start date and end date are required"},
|
{"error": "Start date and end date both are required"},
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -430,11 +448,6 @@ class CycleDateCheckEndpoint(BaseAPIView):
|
|||||||
project_id=project_id,
|
project_id=project_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
if cycle_id:
|
|
||||||
cycles = cycles.filter(
|
|
||||||
~Q(pk=cycle_id),
|
|
||||||
)
|
|
||||||
|
|
||||||
if cycles.exists():
|
if cycles.exists():
|
||||||
return Response(
|
return Response(
|
||||||
{
|
{
|
||||||
@ -508,10 +521,25 @@ class CurrentUpcomingCyclesEndpoint(BaseAPIView):
|
|||||||
filter=Q(issue_cycle__issue__state__group="backlog"),
|
filter=Q(issue_cycle__issue__state__group="backlog"),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
.annotate(total_estimates=Sum("issue_cycle__issue__estimate_point"))
|
||||||
|
.annotate(
|
||||||
|
completed_estimates=Sum(
|
||||||
|
"issue_cycle__issue__estimate_point",
|
||||||
|
filter=Q(issue_cycle__issue__state__group="completed"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.annotate(
|
||||||
|
started_estimates=Sum(
|
||||||
|
"issue_cycle__issue__estimate_point",
|
||||||
|
filter=Q(issue_cycle__issue__state__group="started"),
|
||||||
|
)
|
||||||
|
)
|
||||||
.prefetch_related(
|
.prefetch_related(
|
||||||
Prefetch(
|
Prefetch(
|
||||||
"issue_cycle__issue__assignees",
|
"issue_cycle__issue__assignees",
|
||||||
queryset=User.objects.only("avatar", "first_name", "id").distinct(),
|
queryset=User.objects.only(
|
||||||
|
"avatar", "first_name", "id"
|
||||||
|
).distinct(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.order_by("name", "-is_favorite")
|
.order_by("name", "-is_favorite")
|
||||||
@ -558,10 +586,25 @@ class CurrentUpcomingCyclesEndpoint(BaseAPIView):
|
|||||||
filter=Q(issue_cycle__issue__state__group="backlog"),
|
filter=Q(issue_cycle__issue__state__group="backlog"),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
.annotate(total_estimates=Sum("issue_cycle__issue__estimate_point"))
|
||||||
|
.annotate(
|
||||||
|
completed_estimates=Sum(
|
||||||
|
"issue_cycle__issue__estimate_point",
|
||||||
|
filter=Q(issue_cycle__issue__state__group="completed"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.annotate(
|
||||||
|
started_estimates=Sum(
|
||||||
|
"issue_cycle__issue__estimate_point",
|
||||||
|
filter=Q(issue_cycle__issue__state__group="started"),
|
||||||
|
)
|
||||||
|
)
|
||||||
.prefetch_related(
|
.prefetch_related(
|
||||||
Prefetch(
|
Prefetch(
|
||||||
"issue_cycle__issue__assignees",
|
"issue_cycle__issue__assignees",
|
||||||
queryset=User.objects.only("avatar", "first_name", "id").distinct(),
|
queryset=User.objects.only(
|
||||||
|
"avatar", "first_name", "id"
|
||||||
|
).distinct(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.order_by("name", "-is_favorite")
|
.order_by("name", "-is_favorite")
|
||||||
@ -576,7 +619,7 @@ class CurrentUpcomingCyclesEndpoint(BaseAPIView):
|
|||||||
)
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
capture_exception(e)
|
||||||
return Response(
|
return Response(
|
||||||
{"error": "Something went wrong please try again later"},
|
{"error": "Something went wrong please try again later"},
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
@ -637,10 +680,25 @@ class CompletedCyclesEndpoint(BaseAPIView):
|
|||||||
filter=Q(issue_cycle__issue__state__group="backlog"),
|
filter=Q(issue_cycle__issue__state__group="backlog"),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
.annotate(total_estimates=Sum("issue_cycle__issue__estimate_point"))
|
||||||
|
.annotate(
|
||||||
|
completed_estimates=Sum(
|
||||||
|
"issue_cycle__issue__estimate_point",
|
||||||
|
filter=Q(issue_cycle__issue__state__group="completed"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.annotate(
|
||||||
|
started_estimates=Sum(
|
||||||
|
"issue_cycle__issue__estimate_point",
|
||||||
|
filter=Q(issue_cycle__issue__state__group="started"),
|
||||||
|
)
|
||||||
|
)
|
||||||
.prefetch_related(
|
.prefetch_related(
|
||||||
Prefetch(
|
Prefetch(
|
||||||
"issue_cycle__issue__assignees",
|
"issue_cycle__issue__assignees",
|
||||||
queryset=User.objects.only("avatar", "first_name", "id").distinct(),
|
queryset=User.objects.only(
|
||||||
|
"avatar", "first_name", "id"
|
||||||
|
).distinct(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.order_by("name", "-is_favorite")
|
.order_by("name", "-is_favorite")
|
||||||
@ -718,10 +776,25 @@ class DraftCyclesEndpoint(BaseAPIView):
|
|||||||
filter=Q(issue_cycle__issue__state__group="backlog"),
|
filter=Q(issue_cycle__issue__state__group="backlog"),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
.annotate(total_estimates=Sum("issue_cycle__issue__estimate_point"))
|
||||||
|
.annotate(
|
||||||
|
completed_estimates=Sum(
|
||||||
|
"issue_cycle__issue__estimate_point",
|
||||||
|
filter=Q(issue_cycle__issue__state__group="completed"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.annotate(
|
||||||
|
started_estimates=Sum(
|
||||||
|
"issue_cycle__issue__estimate_point",
|
||||||
|
filter=Q(issue_cycle__issue__state__group="started"),
|
||||||
|
)
|
||||||
|
)
|
||||||
.prefetch_related(
|
.prefetch_related(
|
||||||
Prefetch(
|
Prefetch(
|
||||||
"issue_cycle__issue__assignees",
|
"issue_cycle__issue__assignees",
|
||||||
queryset=User.objects.only("avatar", "first_name", "id").distinct(),
|
queryset=User.objects.only(
|
||||||
|
"avatar", "first_name", "id"
|
||||||
|
).distinct(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.order_by("name", "-is_favorite")
|
.order_by("name", "-is_favorite")
|
||||||
|
Loading…
Reference in New Issue
Block a user