From a0cd7f1198a665165ac81844e1c1ca4b00c4a06a Mon Sep 17 00:00:00 2001 From: Gregor Zurowski Date: Mon, 16 Sep 2024 16:39:39 +0000 Subject: [PATCH 1/2] Prefetch fundraises to avoid individual queries in serialization --- .../views/researchhub_unified_document_views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/researchhub_document/views/researchhub_unified_document_views.py b/src/researchhub_document/views/researchhub_unified_document_views.py index 4323dad63..5d609fb6d 100644 --- a/src/researchhub_document/views/researchhub_unified_document_views.py +++ b/src/researchhub_document/views/researchhub_unified_document_views.py @@ -708,7 +708,7 @@ def get_unified_documents(self, request): date_ranges=[time_scope], ) - documents = self.get_filtered_queryset() + documents = self.get_filtered_queryset().prefetch_related("fundraises") context = self._get_serializer_context() context["hub_id"] = hub_id page = self.paginate_queryset(documents) From 19861f86cadd43e338f283eba2ddd36325f07d9d Mon Sep 17 00:00:00 2001 From: Gregor Zurowski Date: Mon, 16 Sep 2024 16:51:06 +0000 Subject: [PATCH 2/2] [Minor] Use boolean type for checking boolean query string --- .../views/researchhub_unified_document_views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/researchhub_document/views/researchhub_unified_document_views.py b/src/researchhub_document/views/researchhub_unified_document_views.py index 5d609fb6d..c9f8a1726 100644 --- a/src/researchhub_document/views/researchhub_unified_document_views.py +++ b/src/researchhub_document/views/researchhub_unified_document_views.py @@ -679,11 +679,11 @@ def test_get_unified_documents(self, request): def get_unified_documents(self, request): is_anonymous = request.user.is_anonymous query_params = request.query_params - subscribed_hubs = query_params.get("subscribed_hubs", "false") + subscribed_hubs = query_params.get("subscribed_hubs", "false").lower() == "true" filtering = query_params.get("ordering", HOT) time_scope = query_params.get("time", "today") - if subscribed_hubs == "true" and not is_anonymous: + if subscribed_hubs and not is_anonymous: return self._get_subscribed_unified_documents(request) document_request_type = query_params.get("type", "all")