Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Prefetch on update to save some execution time
Tomasz Szymanski874926b13035
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.pyindex ec5fa2262a..fa32a6a4a9 100644--- a/saleor/graphql/product/mutations/products.py+++ b/saleor/graphql/product/mutations/products.py@@ -1031,6 +1031,17 @@ class ProductUpdate(ProductCreate):})+ @classmethod+ def get_instance(cls, info, **data):+ """Prefetch related fields that are needed to process the mutation."""+ object_id = data.get("id")+ if object_id:+ # Prefetches needed by `product_updated` plugin hook+ qs = cls._meta.model.objects.prefetch_related("variants")+ return cls.get_node_or_error(info, object_id, only_type="Product", qs=qs)++ return super().get_instance(info, **data)+@classmethod@transaction.atomicdef save(cls, info, instance, cleaned_input):@@ -1892,4 +1903,5 @@ class ProductSetAvailabilityForPurchase(BaseMutation):product.available_for_purchase = start_dateproduct.save(update_fields=["available_for_purchase", "updated_at"])+ info.context.plugins.product_updated(product)return ProductSetAvailabilityForPurchase(product=product)