Skip to content

Commit 0bf7a4c

Browse files
committed
fix performance issue with attribute that have large numebr of options, do not loop over all options
1 parent d1c848f commit 0bf7a4c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

app/code/Magento/Elasticsearch/Model/Adapter/BatchDataMapper/ProductDataMapper.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,9 @@ private function getValuesLabels(Attribute $attribute, array $attributeValues):
285285
return $attributeLabels;
286286
}
287287

288-
foreach ($options as $option) {
289-
if (\in_array($option->getValue(), $attributeValues)) {
290-
$attributeLabels[] = $option->getLabel();
288+
foreach ($attributeValues as $attributeValue) {
289+
if (isset($options[$attributeValue])) {
290+
$attributeLabels[] = $options[$attributeValue]->getLabel();
291291
}
292292
}
293293

@@ -304,7 +304,11 @@ private function getAttributeOptions(Attribute $attribute): array
304304
{
305305
if (!isset($this->attributeOptionsCache[$attribute->getId()])) {
306306
$options = $attribute->getOptions() ?? [];
307-
$this->attributeOptionsCache[$attribute->getId()] = $options;
307+
$optionsByValue = [];
308+
foreach ($options as $option) {
309+
$optionsByValue[$option->getValue()] = $option;
310+
}
311+
$this->attributeOptionsCache[$attribute->getId()] = $optionsByValue;
308312
}
309313

310314
return $this->attributeOptionsCache[$attribute->getId()];

0 commit comments

Comments
 (0)