Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Performance fix for input_type resolver on AttributeValue (#7396)
Tomasz Szymański2c573fa90db9
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 62f4ac0c59..21c94b90f9 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -100,6 +100,7 @@ All notable, unreleased changes to this project will be documented in this file.- Fix invoice generation - #7376 by @tomaszszymanski129- Allow defining only one field in translations - #7363 by @IKarbowiak- Trigger `checkout_updated` hook for checkout meta mutations - #7392 by @maarcingebala+- Optimize `inputType` resolver on `AttributeValue` type - 7396 by @tomaszszymanski129- Allow filtering pages by ids - #7393 by @IKarbowiak### Breakingdiff --git a/saleor/graphql/attribute/types.py b/saleor/graphql/attribute/types.pyindex 7c6d2a9dfe..d82b88d5f9 100644--- a/saleor/graphql/attribute/types.py+++ b/saleor/graphql/attribute/types.py@@ -2,16 +2,16 @@ import reimport graphene-from ...attribute import AttributeInputType, models+from ...attribute import AttributeInputType, AttributeType, models+from ...core.exceptions import PermissionDenied+from ...core.permissions import PagePermissions, ProductPermissionsfrom ...core.tracing import traced_resolver+from ...graphql.utils import get_user_or_app_from_contextfrom ..core.connection import CountableDjangoObjectTypefrom ..core.enums import MeasurementUnitsEnumfrom ..core.types import Filefrom ..core.types.common import IntRangeInput-from ..decorators import (- check_attribute_required_permissions,- check_attribute_value_required_permissions,-)+from ..decorators import check_attribute_required_permissionsfrom ..meta.types import ObjectWithMetadatafrom ..translations.fields import TranslationFieldfrom ..translations.types import AttributeTranslation, AttributeValueTranslation@@ -46,10 +46,22 @@ class AttributeValue(CountableDjangoObjectType):model = models.AttributeValue@staticmethod- @traced_resolver- @check_attribute_value_required_permissions()- def resolve_input_type(root: models.AttributeValue, *_args):- return root.input_type+ def resolve_input_type(root: models.AttributeValue, info, *_args):+ def _resolve_input_type(attribute):+ requester = get_user_or_app_from_context(info.context)+ if attribute.type == AttributeType.PAGE_TYPE:+ if requester.has_perm(PagePermissions.MANAGE_PAGES):+ return attribute.input_type+ raise PermissionDenied()+ elif requester.has_perm(ProductPermissions.MANAGE_PRODUCTS):+ return attribute.input_type+ raise PermissionDenied()++ return (+ AttributesByAttributeId(info.context)+ .load(root.attribute_id)+ .then(_resolve_input_type)+ )@staticmethod@traced_resolverdiff --git a/saleor/graphql/decorators.py b/saleor/graphql/decorators.pyindex e0764921a1..55a85b1f89 100644--- a/saleor/graphql/decorators.py+++ b/saleor/graphql/decorators.py@@ -110,18 +110,3 @@ def check_attribute_required_permissions():return _permission_required((ProductPermissions.MANAGE_PRODUCTS,), context)return account_passes_test_for_attribute(check_perms)---def check_attribute_value_required_permissions():- """Check attribute value permissions depending on the corresponding attribute type.-- As an value's attribute can belong to the product or to the page,- different permissions need to be checked.- """-- def check_perms(context, attribute_value):- if attribute_value.attribute.type == AttributeType.PAGE_TYPE:- return _permission_required((PagePermissions.MANAGE_PAGES,), context)- return _permission_required((ProductPermissions.MANAGE_PRODUCTS,), context)-- return account_passes_test_for_attribute(check_perms)