From d726344d24f3574b3a15fa742feb804f592509ad Mon Sep 17 00:00:00 2001 From: Antoine Libert Date: Sat, 30 Dec 2023 23:26:34 +0100 Subject: [PATCH] fix(api): replace the build of the ids of documents by a single SQL query. This increases the performance of `/api/documents/` up to 60% on a ~1400 documents database (~600 ms > ~240 ms on laptop). This optimization only applies to the basic "list documents case", not the "search case". --- src/paperless/views.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/paperless/views.py b/src/paperless/views.py index 16423671a..73b383a6f 100644 --- a/src/paperless/views.py +++ b/src/paperless/views.py @@ -56,11 +56,7 @@ class StandardPagination(PageNumberPagination): except Exception: pass else: - for obj in self.page.paginator.object_list: - if hasattr(obj, "id"): - ids.append(obj.id) - elif hasattr(obj, "fields"): - ids.append(obj.fields()["id"]) + ids = self.page.paginator.object_list.values_list("pk", flat=True) return ids def get_paginated_response_schema(self, schema):