Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Reduce number of queries for 'completeCheckout' mutation
IKarbowiak2b49f42663b8
diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.pyindex 7b35d6ed8b..23488b0246 100644--- a/saleor/graphql/checkout/mutations.py+++ b/saleor/graphql/checkout/mutations.py@@ -4,6 +4,7 @@ import graphenefrom django.conf import settingsfrom django.core.exceptions import ObjectDoesNotExist, ValidationErrorfrom django.db import transaction+from django.db.models import Prefetchfrom django.utils import timezonefrom ...checkout import models@@ -29,7 +30,7 @@ from ...core import analyticsfrom ...core.exceptions import InsufficientStockfrom ...core.taxes import TaxErrorfrom ...discount import models as voucher_model-from ...payment import PaymentError, gateway+from ...payment import PaymentError, gateway, models as payment_modelsfrom ...payment.interface import AddressDatafrom ...payment.utils import store_customer_idfrom ...product import models as product_models@@ -644,11 +645,25 @@ class CheckoutComplete(BaseMutation):@classmethoddef perform_mutation(cls, _root, info, checkout_id, store_source):checkout = cls.get_node_or_error(- info, checkout_id, only_type=Checkout, field="checkout_id"+ info,+ checkout_id,+ only_type=Checkout,+ field="checkout_id",+ qs=models.Checkout.objects.prefetch_related(+ "gift_cards",+ "lines",+ Prefetch(+ "payments",+ queryset=payment_models.Payment.objects.prefetch_related(+ "order", "order__lines"+ ),+ ),+ ).select_related("shipping_method", "shipping_method__shipping_zone"),)+ discounts = info.context.discountsuser = info.context.user- clean_checkout(checkout, info.context.discounts)+ clean_checkout(checkout, discounts)payment = checkout.get_last_active_payment()@@ -657,7 +672,7 @@ class CheckoutComplete(BaseMutation):order_data = prepare_order_data(checkout=checkout,tracking_code=analytics.get_client_id(info.context),- discounts=info.context.discounts,+ discounts=discounts,)except InsufficientStock as e:raise ValidationError(