Skip to content

Commit d5a2fb6

Browse files
freddenAleksandr Yegorov
authored andcommitted
Improve performance of indexer
Co-authored-by: Aleksandr Yegorov <a.yegorov@youweagency.com>
1 parent 5a022f6 commit d5a2fb6

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,8 @@ private function getValuesLabels(Attribute $attribute, array $attributeValues, i
370370
return $attributeLabels;
371371
}
372372

373-
foreach ($options as $option) {
374-
if (\in_array($option['value'], $attributeValues)) {
375-
$attributeLabels[] = $option['label'];
376-
}
377-
}
373+
$options = array_intersect_key($options, array_flip($attributeValues));
374+
$attributeLabels = array_column($options, 'label');
378375

379376
return $attributeLabels;
380377
}
@@ -395,6 +392,14 @@ private function getAttributeOptions(Attribute $attribute, int $storeId): array
395392
* $attribute->getOptions() loads options into data objects which can be costly.
396393
*/
397394
$options = $attribute->usesSource() ? $attribute->setStoreId($storeId)->getSource()->getAllOptions() : [];
395+
396+
if (!empty($options)) {
397+
$options = array_combine(
398+
array_column($options, 'value'),
399+
$options
400+
);
401+
}
402+
398403
$this->attributeOptionsCache[$storeId][$attribute->getId()] = $options;
399404
$attribute->setStoreId($attributeStoreId);
400405
}

0 commit comments

Comments
 (0)