Skip to content

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

Update Variant mutations - reduce number of queries

IKarbowiakffeed09843b0
diff --git a/saleor/graphql/product/bulk_mutations/products.py b/saleor/graphql/product/bulk_mutations/products.py
index 343068bfb2..320bc7c3ea 100644
--- a/saleor/graphql/product/bulk_mutations/products.py
+++ b/saleor/graphql/product/bulk_mutations/products.py
@@ -111,7 +111,7 @@ class ProductBulkDelete(ModelBulkDeleteMutation):
@classmethod
def perform_mutation(cls, _root, info, ids, **data):
- nodes_type, pks = resolve_global_ids_to_primary_keys(ids, Product)
+ _, pks = resolve_global_ids_to_primary_keys(ids, Product)
variants = models.ProductVariant.objects.filter(product__pk__in=pks)
# get draft order lines for products
order_line_pks = list(
@@ -363,11 +363,11 @@ class ProductVariantBulkDelete(ModelBulkDeleteMutation):
@classmethod
def perform_mutation(cls, _root, info, ids, **data):
- instances = cls.get_nodes_or_error(ids, "id", ProductVariant)
+ _, pks = resolve_global_ids_to_primary_keys(ids, ProductVariant)
# get draft order lines for variants
order_line_pks = list(
order_models.OrderLine.objects.filter(
- variant__in=instances, order__status=OrderStatus.DRAFT
+ variant__pk__in=pks, order__status=OrderStatus.DRAFT
).values_list("pk", flat=True)
)
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.py
index 59bb85105f..ce3f1d2044 100644
--- a/saleor/graphql/product/mutations/products.py
+++ b/saleor/graphql/product/mutations/products.py
@@ -1402,12 +1402,12 @@ class ProductVariantDelete(ModelDeleteMutation):
@classmethod
def perform_mutation(cls, _root, info, **data):
node_id = data.get("id")
- instance = cls.get_node_or_error(info, node_id, only_type=ProductVariant)
+ variant_pk = from_global_id_strict_type(node_id, ProductVariant, field="pk")
# get draft order lines for variant
line_pks = list(
order_models.OrderLine.objects.filter(
- variant=instance, order__status=OrderStatus.DRAFT
+ variant__pk=variant_pk, order__status=OrderStatus.DRAFT
).values_list("pk", flat=True)
)