From 6a3dd45fc2a6f68ea77a7c9fbe075fc32efbac14 Mon Sep 17 00:00:00 2001 From: "D. Gopal Krishna" Date: Thu, 9 May 2024 15:32:24 +0530 Subject: [PATCH] AREG-106 - fix N+1 query for fts by catalog number --- .../portal/backend/api/repositories/search_repository.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/portal/backend/api/repositories/search_repository.py b/applications/portal/backend/api/repositories/search_repository.py index 15ba8132..1c509652 100644 --- a/applications/portal/backend/api/repositories/search_repository.py +++ b/applications/portal/backend/api/repositories/search_repository.py @@ -48,7 +48,7 @@ def fts_by_catalog_number(search: str, page, size, filters=None): search=vector, ranking=SearchRank(vector, search_query, normalization=Value(1))) .filter(search=search_query, status=STATUS.CURATED, ranking__gte=MIN_CATALOG_RANKING) - ) + ).select_related("vendor").prefetch_related("species").prefetch_related("applications") # if we match catalog_num or cat_alt, we return those results without looking for other fields # as the match is a perfect match or a prefix match depending on the search word,