Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Reduce number of database calls
Adam Janikbbe0d5adfe55
diff --git a/saleor/dashboard/graphql/product/mutations.py b/saleor/dashboard/graphql/product/mutations.pyindex 0091a8dfcb..8d9923ab55 100644--- a/saleor/dashboard/graphql/product/mutations.py+++ b/saleor/dashboard/graphql/product/mutations.py@@ -61,10 +61,11 @@ class BaseProductMutateMixin(BaseMutation):if attributes:form = cls._meta.form_class(**form_kwargs)if form.is_valid():- pt_ids = form.\- instance.product_type.product_attributes.values_list('id')+ attr_slug_id = dict(+ form.instance.product_type.product_attributes.values_list(+ 'slug','id'))form.instance.attributes = get_attributes_dict_from_list(- attributes=attributes, product_type_ids=pt_ids)+ attributes=attributes, attr_slug_id=attr_slug_id)instance = form.save()kwargs = {cls._meta.return_field_name: instance}return cls(errors=[], **kwargs)diff --git a/saleor/dashboard/graphql/utils.py b/saleor/dashboard/graphql/utils.pyindex 2e588a51e9..0f1adce9d7 100644--- a/saleor/dashboard/graphql/utils.py+++ b/saleor/dashboard/graphql/utils.py@@ -4,7 +4,7 @@ from django.utils.text import slugifyfrom ...product.models import AttributeChoiceValue, ProductAttribute-def get_attributes_dict_from_list(attributes, product_type_ids):+def get_attributes_dict_from_list(attributes, attr_slug_id):""":param attributes: list:return: dict@@ -12,9 +12,6 @@ def get_attributes_dict_from_list(attributes, product_type_ids):and converts into dictionary {attr_pk: value_pk}"""attr_ids = {}- attr_slug_id = dict(- ProductAttribute.objects.filter(- id__in=product_type_ids).values_list('slug', 'id'))value_slug_id = dict(AttributeChoiceValue.objects.values_list('name', 'id'))for attribute in attributes: