From 7914bcf486a7ca8c6330bccf5e724d42043dae36 Mon Sep 17 00:00:00 2001 From: pablohashescobar <118773738+pablohashescobar@users.noreply.github.com> Date: Fri, 14 Jul 2023 12:01:38 +0530 Subject: [PATCH] refactor: serializers to avoid getting child items (#1504) * refactor: serializers to avoid getting child items * dev: update issue state serializer to remove n+1 items --- apiserver/plane/api/serializers/issue.py | 6 +++--- apiserver/plane/api/serializers/module.py | 4 ++-- apiserver/plane/api/serializers/project.py | 11 +++-------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/apiserver/plane/api/serializers/issue.py b/apiserver/plane/api/serializers/issue.py index 7376cf0ff..61958d89e 100644 --- a/apiserver/plane/api/serializers/issue.py +++ b/apiserver/plane/api/serializers/issue.py @@ -462,8 +462,8 @@ class IssueAttachmentSerializer(BaseSerializer): # Issue Serializer with state details class IssueStateSerializer(BaseSerializer): - state_detail = StateSerializer(read_only=True, source="state") - project_detail = ProjectSerializer(read_only=True, source="project") + state_detail = StateLiteSerializer(read_only=True, source="state") + project_detail = ProjectLiteSerializer(read_only=True, source="project") label_details = LabelSerializer(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) @@ -477,7 +477,7 @@ class IssueStateSerializer(BaseSerializer): class IssueSerializer(BaseSerializer): - project_detail = ProjectSerializer(read_only=True, source="project") + project_detail = ProjectLiteSerializer(read_only=True, source="project") state_detail = StateSerializer(read_only=True, source="state") parent_detail = IssueFlatSerializer(read_only=True, source="parent") label_details = LabelSerializer(read_only=True, source="labels", many=True) diff --git a/apiserver/plane/api/serializers/module.py b/apiserver/plane/api/serializers/module.py index ea9edd82c..a82a0f39f 100644 --- a/apiserver/plane/api/serializers/module.py +++ b/apiserver/plane/api/serializers/module.py @@ -106,7 +106,7 @@ class ModuleFlatSerializer(BaseSerializer): class ModuleIssueSerializer(BaseSerializer): module_detail = ModuleFlatSerializer(read_only=True, source="module") - issue_detail = IssueStateSerializer(read_only=True, source="issue") + issue_detail = ProjectLiteSerializer(read_only=True, source="issue") sub_issues_count = serializers.IntegerField(read_only=True) class Meta: @@ -151,7 +151,7 @@ class ModuleLinkSerializer(BaseSerializer): class ModuleSerializer(BaseSerializer): - project_detail = ProjectSerializer(read_only=True, source="project") + project_detail = ProjectLiteSerializer(read_only=True, source="project") lead_detail = UserLiteSerializer(read_only=True, source="lead") members_detail = UserLiteSerializer(read_only=True, many=True, source="members") link_module = ModuleLinkSerializer(read_only=True, many=True) diff --git a/apiserver/plane/api/serializers/project.py b/apiserver/plane/api/serializers/project.py index db6021433..641edb07c 100644 --- a/apiserver/plane/api/serializers/project.py +++ b/apiserver/plane/api/serializers/project.py @@ -110,8 +110,8 @@ class ProjectMemberSerializer(BaseSerializer): class ProjectMemberInviteSerializer(BaseSerializer): - project = ProjectSerializer(read_only=True) - workspace = WorkSpaceSerializer(read_only=True) + project = ProjectLiteSerializer(read_only=True) + workspace = WorkspaceLiteSerializer(read_only=True) class Meta: model = ProjectMemberInvite @@ -125,7 +125,7 @@ class ProjectIdentifierSerializer(BaseSerializer): class ProjectFavoriteSerializer(BaseSerializer): - project_detail = ProjectSerializer(source="project", read_only=True) + project_detail = ProjectLiteSerializer(source="project", read_only=True) class Meta: model = ProjectFavorite @@ -136,11 +136,6 @@ class ProjectFavoriteSerializer(BaseSerializer): ] -class ProjectLiteSerializer(BaseSerializer): - class Meta: - model = Project - fields = ["id", "identifier", "name"] - read_only_fields = fields class ProjectMemberLiteSerializer(BaseSerializer):