From 45b2399bd414bca4977a1341dbb1860f0d64454e Mon Sep 17 00:00:00 2001 From: Caleb Godwin Date: Mon, 26 Aug 2024 17:24:22 -0400 Subject: [PATCH] Prefetch IndexedRegulationText and category parents --- solution/backend/content_search/views.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/solution/backend/content_search/views.py b/solution/backend/content_search/views.py index e7524b5cd..4450dd290 100644 --- a/solution/backend/content_search/views.py +++ b/solution/backend/content_search/views.py @@ -13,7 +13,7 @@ ) from resources.utils import get_citation_filter, string_to_bool -from .models import ContentIndex +from .models import ContentIndex, IndexedRegulationText from .serializers import ContentSearchSerializer @@ -133,9 +133,12 @@ def list(self, request, *args, **kwargs): # Prefetch all related data query = query.prefetch_related( + Prefetch("reg_text", IndexedRegulationText.objects.all()), Prefetch("resource", AbstractResource.objects.select_subclasses().prefetch_related( Prefetch("cfr_citations", AbstractCitation.objects.select_subclasses()), - Prefetch("category", AbstractCategory.objects.select_subclasses()), + Prefetch("category", AbstractCategory.objects.select_subclasses().prefetch_related( + Prefetch("parent", AbstractCategory.objects.select_subclasses()), + )), Prefetch("subjects", Subject.objects.all()), )), )