From 26ec7323e54a9256483f97d0383c29cf9fde2721 Mon Sep 17 00:00:00 2001 From: pablohashescobar Date: Tue, 12 Mar 2024 14:52:24 +0530 Subject: [PATCH] dev: add total pages key --- apiserver/plane/utils/paginator.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apiserver/plane/utils/paginator.py b/apiserver/plane/utils/paginator.py index fa503fe87..3eef1d720 100644 --- a/apiserver/plane/utils/paginator.py +++ b/apiserver/plane/utils/paginator.py @@ -145,7 +145,7 @@ class OffsetPaginator: results=results, next=next_cursor, prev=prev_cursor, - hits=None, + hits=count, max_hits=max_hits, ) @@ -197,9 +197,6 @@ class GroupedOffsetPaginator(OffsetPaginator): if offset < 0: raise BadPaginationError("Pagination offset cannot be negative") - # Get the queryset - queryset = self.queryset - # Compute the results results = {} queryset = queryset.annotate( @@ -211,7 +208,7 @@ class GroupedOffsetPaginator(OffsetPaginator): ) # Filter the results - results = queryset.filter(row_number__gte=offset, row_number__lt=stop) + results = queryset.filter(row_number__gt=offset, row_number__lt=stop) # Adjust cursors based on the grouped results for pagination next_cursor = Cursor( @@ -227,6 +224,8 @@ class GroupedOffsetPaginator(OffsetPaginator): page > 0, ) + count = queryset.count() + # Optionally, calculate the total count and max_hits if needed # This might require adjustments based on specific use cases max_hits = math.ceil( @@ -243,7 +242,7 @@ class GroupedOffsetPaginator(OffsetPaginator): results=results, next=next_cursor, prev=prev_cursor, - hits=None, + hits=count, max_hits=max_hits, ) @@ -417,6 +416,7 @@ class BasePaginator: response = Response( { "grouped_by": group_by_field_name, + "total_count": (cursor_result.hits), "next_cursor": str(cursor_result.next), "prev_cursor": str(cursor_result.prev), "next_page_results": cursor_result.next.has_results,