Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Prefetch data only when necessary

Mira Szewczyk4264b1bc9718
diff --git a/saleor/graphql/stock/filters.py b/saleor/graphql/stock/filters.py
index 58abdbea7a..0a2cd593f5 100644
--- a/saleor/graphql/stock/filters.py
+++ b/saleor/graphql/stock/filters.py
@@ -12,10 +12,10 @@ def filter_search(qs, _, value):
"warehouse__name",
"warehouse__company_name",
]
- qs = qs.select_related("product_variant", "warehouse").prefetch_related(
- "product_variant__product"
- )
if value:
+ qs = qs.select_related("product_variant", "warehouse").prefetch_related(
+ "product_variant__product"
+ )
qs = filter_by_query_param(qs, value, search_fields)
return qs
diff --git a/saleor/graphql/warehouse/filters.py b/saleor/graphql/warehouse/filters.py
index bc0b8869b5..23fee1f970 100644
--- a/saleor/graphql/warehouse/filters.py
+++ b/saleor/graphql/warehouse/filters.py
@@ -20,9 +20,9 @@ def filter_search(qs, _, value):
"address__postal_code",
"address__phone",
]
- qs = prefech_qs_for_filter(qs)
if value:
+ qs = prefech_qs_for_filter(qs)
qs = filter_by_query_param(qs, value, search_fields)
return qs