forked from github/plane
perf: update issue serializer (#534)
This commit is contained in:
parent
5d67029b5a
commit
32ab7951f7
@ -18,8 +18,9 @@ from .project import (
|
|||||||
ProjectMemberInviteSerializer,
|
ProjectMemberInviteSerializer,
|
||||||
ProjectIdentifierSerializer,
|
ProjectIdentifierSerializer,
|
||||||
ProjectFavoriteSerializer,
|
ProjectFavoriteSerializer,
|
||||||
|
ProjectLiteSerializer,
|
||||||
)
|
)
|
||||||
from .state import StateSerializer
|
from .state import StateSerializer, StateLiteSerializer
|
||||||
from .shortcut import ShortCutSerializer
|
from .shortcut import ShortCutSerializer
|
||||||
from .view import IssueViewSerializer, IssueViewFavoriteSerializer
|
from .view import IssueViewSerializer, IssueViewFavoriteSerializer
|
||||||
from .cycle import CycleSerializer, CycleIssueSerializer, CycleFavoriteSerializer
|
from .cycle import CycleSerializer, CycleIssueSerializer, CycleFavoriteSerializer
|
||||||
@ -38,6 +39,7 @@ from .issue import (
|
|||||||
IssueFlatSerializer,
|
IssueFlatSerializer,
|
||||||
IssueStateSerializer,
|
IssueStateSerializer,
|
||||||
IssueLinkSerializer,
|
IssueLinkSerializer,
|
||||||
|
IssueLiteSerializer,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .module import (
|
from .module import (
|
||||||
|
@ -4,9 +4,9 @@ from rest_framework import serializers
|
|||||||
# Module imports
|
# Module imports
|
||||||
from .base import BaseSerializer
|
from .base import BaseSerializer
|
||||||
from .user import UserLiteSerializer
|
from .user import UserLiteSerializer
|
||||||
from .state import StateSerializer
|
from .state import StateSerializer, StateLiteSerializer
|
||||||
from .user import UserLiteSerializer
|
from .user import UserLiteSerializer
|
||||||
from .project import ProjectSerializer
|
from .project import ProjectSerializer, ProjectLiteSerializer
|
||||||
from .workspace import WorkSpaceSerializer
|
from .workspace import WorkSpaceSerializer
|
||||||
from plane.db.models import (
|
from plane.db.models import (
|
||||||
User,
|
User,
|
||||||
@ -305,6 +305,16 @@ class LabelSerializer(BaseSerializer):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class LabelLiteSerializer(BaseSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Label
|
||||||
|
fields = [
|
||||||
|
"id",
|
||||||
|
"name",
|
||||||
|
"color",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class IssueLabelSerializer(BaseSerializer):
|
class IssueLabelSerializer(BaseSerializer):
|
||||||
# label_details = LabelSerializer(read_only=True, source="label")
|
# label_details = LabelSerializer(read_only=True, source="label")
|
||||||
|
|
||||||
@ -468,3 +478,26 @@ class IssueSerializer(BaseSerializer):
|
|||||||
"created_at",
|
"created_at",
|
||||||
"updated_at",
|
"updated_at",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class IssueLiteSerializer(BaseSerializer):
|
||||||
|
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||||
|
state_detail = StateLiteSerializer(read_only=True, source="state")
|
||||||
|
label_details = LabelLiteSerializer(read_only=True, source="labels", many=True)
|
||||||
|
assignee_details = UserLiteSerializer(read_only=True, source="assignees", many=True)
|
||||||
|
sub_issues_count = serializers.IntegerField(read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Issue
|
||||||
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"start_date",
|
||||||
|
"target_date",
|
||||||
|
"completed_at",
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"created_by",
|
||||||
|
"updated_by",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
]
|
||||||
|
@ -118,3 +118,10 @@ class ProjectFavoriteSerializer(BaseSerializer):
|
|||||||
"workspace",
|
"workspace",
|
||||||
"user",
|
"user",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectLiteSerializer(BaseSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Project
|
||||||
|
fields = ["id", "identifier", "name"]
|
||||||
|
read_only_fields = fields
|
||||||
|
@ -12,3 +12,15 @@ class StateSerializer(BaseSerializer):
|
|||||||
"workspace",
|
"workspace",
|
||||||
"project",
|
"project",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class StateLiteSerializer(BaseSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = State
|
||||||
|
fields = [
|
||||||
|
"id",
|
||||||
|
"name",
|
||||||
|
"color",
|
||||||
|
"group",
|
||||||
|
]
|
||||||
|
read_only_fields = fields
|
||||||
|
@ -26,6 +26,7 @@ from plane.api.serializers import (
|
|||||||
LabelSerializer,
|
LabelSerializer,
|
||||||
IssueFlatSerializer,
|
IssueFlatSerializer,
|
||||||
IssueLinkSerializer,
|
IssueLinkSerializer,
|
||||||
|
IssueLiteSerializer,
|
||||||
)
|
)
|
||||||
from plane.api.permissions import (
|
from plane.api.permissions import (
|
||||||
ProjectEntityPermission,
|
ProjectEntityPermission,
|
||||||
@ -136,40 +137,6 @@ class IssueViewSet(BaseViewSet):
|
|||||||
.select_related("parent")
|
.select_related("parent")
|
||||||
.prefetch_related("assignees")
|
.prefetch_related("assignees")
|
||||||
.prefetch_related("labels")
|
.prefetch_related("labels")
|
||||||
.prefetch_related(
|
|
||||||
Prefetch(
|
|
||||||
"blocked_issues",
|
|
||||||
queryset=IssueBlocker.objects.select_related("blocked_by", "block"),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.prefetch_related(
|
|
||||||
Prefetch(
|
|
||||||
"blocker_issues",
|
|
||||||
queryset=IssueBlocker.objects.select_related("block", "blocked_by"),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.prefetch_related(
|
|
||||||
Prefetch(
|
|
||||||
"issue_cycle",
|
|
||||||
queryset=CycleIssue.objects.select_related("cycle", "issue"),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.prefetch_related(
|
|
||||||
Prefetch(
|
|
||||||
"issue_module",
|
|
||||||
queryset=ModuleIssue.objects.select_related(
|
|
||||||
"module", "issue"
|
|
||||||
).prefetch_related("module__members"),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.prefetch_related(
|
|
||||||
Prefetch(
|
|
||||||
"issue_link",
|
|
||||||
queryset=IssueLink.objects.select_related("issue").select_related(
|
|
||||||
"created_by"
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def list(self, request, slug, project_id):
|
def list(self, request, slug, project_id):
|
||||||
@ -189,7 +156,7 @@ class IssueViewSet(BaseViewSet):
|
|||||||
else issue_queryset.filter(parent__isnull=True)
|
else issue_queryset.filter(parent__isnull=True)
|
||||||
)
|
)
|
||||||
|
|
||||||
issues = IssueSerializer(issue_queryset, many=True).data
|
issues = IssueLiteSerializer(issue_queryset, many=True).data
|
||||||
|
|
||||||
## Grouping the results
|
## Grouping the results
|
||||||
group_by = request.GET.get("group_by", False)
|
group_by = request.GET.get("group_by", False)
|
||||||
@ -201,7 +168,6 @@ class IssueViewSet(BaseViewSet):
|
|||||||
return Response(issues, status=status.HTTP_200_OK)
|
return Response(issues, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
|
||||||
capture_exception(e)
|
capture_exception(e)
|
||||||
return Response(
|
return Response(
|
||||||
{"error": "Something went wrong please try again later"},
|
{"error": "Something went wrong please try again later"},
|
||||||
@ -239,6 +205,17 @@ class IssueViewSet(BaseViewSet):
|
|||||||
{"error": "Project was not found"}, status=status.HTTP_404_NOT_FOUND
|
{"error": "Project was not found"}, status=status.HTTP_404_NOT_FOUND
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def retrieve(self, request, slug, project_id, pk=None):
|
||||||
|
try:
|
||||||
|
issue = Issue.objects.get(
|
||||||
|
workspace__slug=slug, project_id=project_id, pk=pk
|
||||||
|
)
|
||||||
|
return Response(IssueSerializer(issue).data, status=status.HTTP_200_OK)
|
||||||
|
except Issue.DoesNotExist:
|
||||||
|
return Response(
|
||||||
|
{"error": "Issue Does not exist"}, status=status.HTTP_404_NOT_FOUND
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class UserWorkSpaceIssues(BaseAPIView):
|
class UserWorkSpaceIssues(BaseAPIView):
|
||||||
def get(self, request, slug):
|
def get(self, request, slug):
|
||||||
@ -257,45 +234,9 @@ class UserWorkSpaceIssues(BaseAPIView):
|
|||||||
.select_related("parent")
|
.select_related("parent")
|
||||||
.prefetch_related("assignees")
|
.prefetch_related("assignees")
|
||||||
.prefetch_related("labels")
|
.prefetch_related("labels")
|
||||||
.prefetch_related(
|
|
||||||
Prefetch(
|
|
||||||
"blocked_issues",
|
|
||||||
queryset=IssueBlocker.objects.select_related(
|
|
||||||
"blocked_by", "block"
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.prefetch_related(
|
|
||||||
Prefetch(
|
|
||||||
"blocker_issues",
|
|
||||||
queryset=IssueBlocker.objects.select_related(
|
|
||||||
"block", "blocked_by"
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.prefetch_related(
|
|
||||||
Prefetch(
|
|
||||||
"issue_cycle",
|
|
||||||
queryset=CycleIssue.objects.select_related("cycle", "issue"),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.prefetch_related(
|
|
||||||
Prefetch(
|
|
||||||
"issue_module",
|
|
||||||
queryset=ModuleIssue.objects.select_related("module", "issue"),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.prefetch_related(
|
|
||||||
Prefetch(
|
|
||||||
"issue_link",
|
|
||||||
queryset=IssueLink.objects.select_related(
|
|
||||||
"issue"
|
|
||||||
).select_related("created_by"),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.order_by("-created_at")
|
.order_by("-created_at")
|
||||||
)
|
)
|
||||||
serializer = IssueSerializer(issues, many=True)
|
serializer = IssueLiteSerializer(issues, many=True)
|
||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
capture_exception(e)
|
capture_exception(e)
|
||||||
@ -625,37 +566,9 @@ class SubIssuesEndpoint(BaseAPIView):
|
|||||||
.select_related("parent")
|
.select_related("parent")
|
||||||
.prefetch_related("assignees")
|
.prefetch_related("assignees")
|
||||||
.prefetch_related("labels")
|
.prefetch_related("labels")
|
||||||
.prefetch_related(
|
|
||||||
Prefetch(
|
|
||||||
"blocked_issues",
|
|
||||||
queryset=IssueBlocker.objects.select_related(
|
|
||||||
"blocked_by", "block"
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.prefetch_related(
|
|
||||||
Prefetch(
|
|
||||||
"blocker_issues",
|
|
||||||
queryset=IssueBlocker.objects.select_related(
|
|
||||||
"block", "blocked_by"
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.prefetch_related(
|
|
||||||
Prefetch(
|
|
||||||
"issue_cycle",
|
|
||||||
queryset=CycleIssue.objects.select_related("cycle", "issue"),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.prefetch_related(
|
|
||||||
Prefetch(
|
|
||||||
"issue_module",
|
|
||||||
queryset=ModuleIssue.objects.select_related("module", "issue"),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
serializer = IssueSerializer(sub_issues, many=True)
|
serializer = IssueLiteSerializer(sub_issues, many=True)
|
||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
capture_exception(e)
|
capture_exception(e)
|
||||||
|
@ -26,7 +26,7 @@ from plane.api.serializers import (
|
|||||||
PageSerializer,
|
PageSerializer,
|
||||||
PageBlockSerializer,
|
PageBlockSerializer,
|
||||||
PageFavoriteSerializer,
|
PageFavoriteSerializer,
|
||||||
IssueSerializer,
|
IssueLiteSerializer,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -217,7 +217,7 @@ class CreateIssueFromPageBlockEndpoint(BaseAPIView):
|
|||||||
page_block.issue = issue
|
page_block.issue = issue
|
||||||
page_block.save()
|
page_block.save()
|
||||||
|
|
||||||
return Response(IssueSerializer(issue).data, status=status.HTTP_200_OK)
|
return Response(IssueLiteSerializer(issue).data, status=status.HTTP_200_OK)
|
||||||
except PageBlock.DoesNotExist:
|
except PageBlock.DoesNotExist:
|
||||||
return Response(
|
return Response(
|
||||||
{"error": "Page Block does not exist"}, status=status.HTTP_404_NOT_FOUND
|
{"error": "Page Block does not exist"}, status=status.HTTP_404_NOT_FOUND
|
||||||
|
@ -11,7 +11,7 @@ from sentry_sdk import capture_exception
|
|||||||
from . import BaseViewSet, BaseAPIView
|
from . import BaseViewSet, BaseAPIView
|
||||||
from plane.api.serializers import (
|
from plane.api.serializers import (
|
||||||
IssueViewSerializer,
|
IssueViewSerializer,
|
||||||
IssueSerializer,
|
IssueLiteSerializer,
|
||||||
IssueViewFavoriteSerializer,
|
IssueViewFavoriteSerializer,
|
||||||
)
|
)
|
||||||
from plane.api.permissions import ProjectEntityPermission
|
from plane.api.permissions import ProjectEntityPermission
|
||||||
@ -81,47 +81,9 @@ class ViewIssuesEndpoint(BaseAPIView):
|
|||||||
.select_related("parent")
|
.select_related("parent")
|
||||||
.prefetch_related("assignees")
|
.prefetch_related("assignees")
|
||||||
.prefetch_related("labels")
|
.prefetch_related("labels")
|
||||||
.prefetch_related(
|
|
||||||
Prefetch(
|
|
||||||
"blocked_issues",
|
|
||||||
queryset=IssueBlocker.objects.select_related(
|
|
||||||
"blocked_by", "block"
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.prefetch_related(
|
|
||||||
Prefetch(
|
|
||||||
"blocker_issues",
|
|
||||||
queryset=IssueBlocker.objects.select_related(
|
|
||||||
"block", "blocked_by"
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.prefetch_related(
|
|
||||||
Prefetch(
|
|
||||||
"issue_cycle",
|
|
||||||
queryset=CycleIssue.objects.select_related("cycle", "issue"),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.prefetch_related(
|
|
||||||
Prefetch(
|
|
||||||
"issue_module",
|
|
||||||
queryset=ModuleIssue.objects.select_related(
|
|
||||||
"module", "issue"
|
|
||||||
).prefetch_related("module__members"),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.prefetch_related(
|
|
||||||
Prefetch(
|
|
||||||
"issue_link",
|
|
||||||
queryset=IssueLink.objects.select_related(
|
|
||||||
"issue"
|
|
||||||
).select_related("created_by"),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
serializer = IssueSerializer(issues, many=True)
|
serializer = IssueLiteSerializer(issues, many=True)
|
||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||||
except IssueView.DoesNotExist:
|
except IssueView.DoesNotExist:
|
||||||
return Response(
|
return Response(
|
||||||
|
Loading…
Reference in New Issue
Block a user