Skip to content

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

Don't iterate over all values trying to find one

Artur Smętdd4329774036
diff --git a/saleor/product/utils.py b/saleor/product/utils.py
index 96ed05ba31..2e5aef5e93 100644
--- a/saleor/product/utils.py
+++ b/saleor/product/utils.py
@@ -3,12 +3,10 @@ def get_attributes_display_map(variant, attributes):
for attribute in attributes:
value = variant.get_attribute(attribute.pk)
if value:
- choices = attribute.values.all()
- if choices:
- for choice in attribute.values.all():
- if choice.pk == value:
- display[attribute.pk] = choice
- break
+ choices = {a.pk: a for a in attribute.values.all()}
+ attr = choices.get(value)
+ if attr:
+ display[attribute.pk] = attr
else:
display[attribute.pk] = value
return display