Skip to content

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

Optimize queries

Mira Szewczykf32f4fdfea8c
diff --git a/saleor/graphql/product/types/products.py b/saleor/graphql/product/types/products.py
index acc6a5aa04..02036b1956 100644
--- a/saleor/graphql/product/types/products.py
+++ b/saleor/graphql/product/types/products.py
@@ -293,10 +293,13 @@ class ProductVariant(CountableDjangoObjectType, MetadataObjectType):
@staticmethod
def resolve_stock(root: models.ProductVariant, info, country=None):
- stock = root.stock.annotate_available_quantity()
if country is None:
- return stock.all()
- return stock.for_country(country)
+ return gql_optimizer.query(
+ root.stock.annotate_available_quantity().all(), info
+ )
+ return gql_optimizer.query(
+ root.stock.annotate_available_quantity().for_country("country").all(), info
+ )
@staticmethod
@permission_required(ProductPermissions.MANAGE_PRODUCTS)
diff --git a/saleor/graphql/warehouse/schema.py b/saleor/graphql/warehouse/schema.py
index 59b419c04c..0ff35ce134 100644
--- a/saleor/graphql/warehouse/schema.py
+++ b/saleor/graphql/warehouse/schema.py
@@ -38,7 +38,7 @@ class WarehouseQueries(graphene.ObjectType):
@permission_required(ProductPermissions.MANAGE_PRODUCTS)
def resolve_warehouses(self, info, **kwargs):
- qs = models.Warehouse.objects.select_related("address").all()
+ qs = models.Warehouse.objects.all()
return gql_optimizer.query(qs, info)