From 5bf739d228d070fc228d29bd7d295b7abbedc7ea Mon Sep 17 00:00:00 2001 From: NarayanBavisetti Date: Tue, 13 Feb 2024 15:19:48 +0530 Subject: [PATCH] fix: issues paginated --- apiserver/plane/app/views/cycle.py | 9 +++-- apiserver/plane/app/views/issue.py | 34 ++++++++++++------- apiserver/plane/app/views/module.py | 9 +++-- apiserver/plane/app/views/view.py | 9 +++-- apiserver/plane/app/views/workspace.py | 11 +++--- .../plane/bgtasks/email_notification_task.py | 2 ++ 6 files changed, 48 insertions(+), 26 deletions(-) diff --git a/apiserver/plane/app/views/cycle.py b/apiserver/plane/app/views/cycle.py index 63d8d28ae..ef11d4dd8 100644 --- a/apiserver/plane/app/views/cycle.py +++ b/apiserver/plane/app/views/cycle.py @@ -628,10 +628,13 @@ class CycleIssueViewSet(WebhookMixin, BaseViewSet): ) ) ) - serializer = IssueSerializer( - issues, many=True, fields=fields if fields else None + return self.paginate( + request=request, + queryset=issues, + on_results=lambda issues: IssueSerializer( + issues, many=True, fields=fields if fields else None, expand=self.expand + ).data, ) - return Response(serializer.data, status=status.HTTP_200_OK) def create(self, request, slug, project_id, cycle_id): issues = request.data.get("issues", []) diff --git a/apiserver/plane/app/views/issue.py b/apiserver/plane/app/views/issue.py index c8845150a..a4dc17e58 100644 --- a/apiserver/plane/app/views/issue.py +++ b/apiserver/plane/app/views/issue.py @@ -224,10 +224,13 @@ class IssueViewSet(WebhookMixin, BaseViewSet): else: issue_queryset = issue_queryset.order_by(order_by_param) - issues = IssueSerializer( - issue_queryset, many=True, fields=self.fields, expand=self.expand - ).data - return Response(issues, status=status.HTTP_200_OK) + return self.paginate( + request=request, + queryset=issue_queryset, + on_results=lambda issues: IssueSerializer( + issues, many=True, fields=self.fields, expand=self.expand + ).data, + ) def create(self, request, slug, project_id): project = Project.objects.get(pk=project_id) @@ -1202,11 +1205,13 @@ class IssueArchiveViewSet(BaseViewSet): if show_sub_issues == "true" else issue_queryset.filter(parent__isnull=True) ) - - issues = IssueSerializer( - issue_queryset, many=True, fields=fields if fields else None - ).data - return Response(issues, status=status.HTTP_200_OK) + return self.paginate( + request=request, + queryset=issue_queryset, + on_results=lambda issues: IssueSerializer( + issues, many=True, fields=fields if fields else None, expand=self.expand + ).data, + ) def retrieve(self, request, slug, project_id, pk=None): issue = Issue.objects.get( @@ -1793,10 +1798,13 @@ class IssueDraftViewSet(BaseViewSet): else: issue_queryset = issue_queryset.order_by(order_by_param) - issues = IssueSerializer( - issue_queryset, many=True, fields=fields if fields else None - ).data - return Response(issues, status=status.HTTP_200_OK) + return self.paginate( + request=request, + queryset=issue_queryset, + on_results=lambda issues: IssueSerializer( + issues, many=True, fields=fields if fields else None, expand=self.expand + ).data, + ) def create(self, request, slug, project_id): project = Project.objects.get(pk=project_id) diff --git a/apiserver/plane/app/views/module.py b/apiserver/plane/app/views/module.py index 4792a1f79..eb847755b 100644 --- a/apiserver/plane/app/views/module.py +++ b/apiserver/plane/app/views/module.py @@ -376,10 +376,13 @@ class ModuleIssueViewSet(WebhookMixin, BaseViewSet): ] filters = issue_filters(request.query_params, "GET") issue_queryset = self.get_queryset().filter(**filters) - serializer = IssueSerializer( - issue_queryset, many=True, fields=fields if fields else None + return self.paginate( + request=request, + queryset=issue_queryset, + on_results=lambda issues: IssueSerializer( + issues, many=True, fields=fields if fields else None, expand=self.expand + ).data, ) - return Response(serializer.data, status=status.HTTP_200_OK) # create multiple issues inside a module def create_module_issues(self, request, slug, project_id, module_id): diff --git a/apiserver/plane/app/views/view.py b/apiserver/plane/app/views/view.py index 27f31f7a9..f6607d7ef 100644 --- a/apiserver/plane/app/views/view.py +++ b/apiserver/plane/app/views/view.py @@ -207,10 +207,13 @@ class GlobalViewIssuesViewSet(BaseViewSet): else: issue_queryset = issue_queryset.order_by(order_by_param) - serializer = IssueSerializer( - issue_queryset, many=True, fields=fields if fields else None + return self.paginate( + request=request, + queryset=issue_queryset, + on_results=lambda issues: IssueSerializer( + issues, many=True, fields=fields if fields else None, expand=self.expand + ).data, ) - return Response(serializer.data, status=status.HTTP_200_OK) class IssueViewViewSet(BaseViewSet): diff --git a/apiserver/plane/app/views/workspace.py b/apiserver/plane/app/views/workspace.py index f4d3dbbb5..a921c16ca 100644 --- a/apiserver/plane/app/views/workspace.py +++ b/apiserver/plane/app/views/workspace.py @@ -1433,10 +1433,13 @@ class WorkspaceUserProfileIssuesEndpoint(BaseAPIView): else: issue_queryset = issue_queryset.order_by(order_by_param) - issues = IssueSerializer( - issue_queryset, many=True, fields=fields if fields else None - ).data - return Response(issues, status=status.HTTP_200_OK) + return self.paginate( + request=request, + queryset=issue_queryset, + on_results=lambda issues: IssueSerializer( + issues, many=True, fields=fields if fields else None, expand=self.expand + ).data, + ) class WorkspaceLabelsEndpoint(BaseAPIView): diff --git a/apiserver/plane/bgtasks/email_notification_task.py b/apiserver/plane/bgtasks/email_notification_task.py index 9e9b348e1..a5ae3341f 100644 --- a/apiserver/plane/bgtasks/email_notification_task.py +++ b/apiserver/plane/bgtasks/email_notification_task.py @@ -147,6 +147,8 @@ def send_email_notification( issue_id, notification_data, receiver_id, email_notification_ids ): try: + if not issue_id: + return ri = redis_instance() base_api = (ri.get(str(issue_id)).decode()) data = create_payload(notification_data=notification_data)