From 0bf7a4c1b87cf0a738ab17ad76a4cb5b46443167 Mon Sep 17 00:00:00 2001 From: Behnam Shayani Date: Sun, 3 Nov 2019 20:43:31 +0100 Subject: [PATCH 1/2] fix performance issue with attribute that have large numebr of options, do not loop over all options --- .../Adapter/BatchDataMapper/ProductDataMapper.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Elasticsearch/Model/Adapter/BatchDataMapper/ProductDataMapper.php b/app/code/Magento/Elasticsearch/Model/Adapter/BatchDataMapper/ProductDataMapper.php index 270ca37e2d42c..19b553dd05f08 100644 --- a/app/code/Magento/Elasticsearch/Model/Adapter/BatchDataMapper/ProductDataMapper.php +++ b/app/code/Magento/Elasticsearch/Model/Adapter/BatchDataMapper/ProductDataMapper.php @@ -285,9 +285,9 @@ private function getValuesLabels(Attribute $attribute, array $attributeValues): return $attributeLabels; } - foreach ($options as $option) { - if (\in_array($option->getValue(), $attributeValues)) { - $attributeLabels[] = $option->getLabel(); + foreach ($attributeValues as $attributeValue) { + if (isset($options[$attributeValue])) { + $attributeLabels[] = $options[$attributeValue]->getLabel(); } } @@ -304,7 +304,11 @@ private function getAttributeOptions(Attribute $attribute): array { if (!isset($this->attributeOptionsCache[$attribute->getId()])) { $options = $attribute->getOptions() ?? []; - $this->attributeOptionsCache[$attribute->getId()] = $options; + $optionsByValue = []; + foreach ($options as $option) { + $optionsByValue[$option->getValue()] = $option; + } + $this->attributeOptionsCache[$attribute->getId()] = $optionsByValue; } return $this->attributeOptionsCache[$attribute->getId()]; From 2b5b9860c395ae85e6c1dc4a736571c9b8985e55 Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Mon, 4 Nov 2019 13:33:44 +0200 Subject: [PATCH 2/2] magento/magento2#25452 Elastic Search 5 Indexing Performance Issue Fix static tests --- .../Adapter/BatchDataMapper/ProductDataMapper.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Elasticsearch/Model/Adapter/BatchDataMapper/ProductDataMapper.php b/app/code/Magento/Elasticsearch/Model/Adapter/BatchDataMapper/ProductDataMapper.php index 19b553dd05f08..7b0f9cfe4b274 100644 --- a/app/code/Magento/Elasticsearch/Model/Adapter/BatchDataMapper/ProductDataMapper.php +++ b/app/code/Magento/Elasticsearch/Model/Adapter/BatchDataMapper/ProductDataMapper.php @@ -252,9 +252,14 @@ private function prepareAttributeValues( */ private function prepareMultiselectValues(array $values): array { - return \array_merge(...\array_map(function (string $value) { - return \explode(',', $value); - }, $values)); + return \array_merge( + ...\array_map( + function (string $value) { + return \explode(',', $value); + }, + $values + ) + ); } /**