From affecea882bbaaf47bd15649cc807b01672bfa3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Bajsarowicz?= Date: Thu, 6 Aug 2026 01:23:57 +0200 Subject: [PATCH] Build flat table column and index maps in one array_merge call getFlatColumns() and getFlatIndexes() merged every attribute's contribution into the accumulated map on each iteration, so each iteration copied the whole map built so far. Both loops run once per flat attribute, which makes the cost grow with the square of the attribute count. Collect the per-attribute maps and merge them once with argument unpacking. The merge order is unchanged, so a later attribute still overrides an earlier key exactly as before, and the phpcs:ignore annotations for Magento2.Performance.ForeachArrayMerge are no longer needed. --- .../Magento/Catalog/Helper/Product/Flat/Indexer.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Catalog/Helper/Product/Flat/Indexer.php b/app/code/Magento/Catalog/Helper/Product/Flat/Indexer.php index 040200f536243..9ae1ca79d839d 100644 --- a/app/code/Magento/Catalog/Helper/Product/Flat/Indexer.php +++ b/app/code/Magento/Catalog/Helper/Product/Flat/Indexer.php @@ -246,7 +246,7 @@ public function isAddChildData() public function getFlatColumns() { if ($this->_columns === null) { - $this->_columns = $this->getFlatColumnsDdlDefinition(); + $columnsPerAttribute = [$this->getFlatColumnsDdlDefinition()]; foreach ($this->getAttributes() as $attribute) { /** @var $attribute \Magento\Eav\Model\Entity\Attribute\AbstractAttribute */ $columns = $attribute->setFlatAddFilterableAttributes( @@ -255,10 +255,10 @@ public function getFlatColumns() $this->isAddChildData() )->getFlatColumns(); if ($columns !== null) { - // phpcs:ignore Magento2.Performance.ForeachArrayMerge - $this->_columns = array_merge($this->_columns, $columns); + $columnsPerAttribute[] = $columns; } } + $this->_columns = array_merge(...$columnsPerAttribute); } return $this->_columns; } @@ -409,6 +409,7 @@ public function getFlatIndexes() 'fields' => ['attribute_set_id'], ]; + $indexesPerAttribute = [$this->_indexes]; foreach ($this->getAttributes() as $attribute) { /** @var $attribute \Magento\Eav\Model\Entity\Attribute */ $indexes = $attribute->setFlatAddFilterableAttributes( @@ -417,10 +418,10 @@ public function getFlatIndexes() $this->isAddChildData() )->getFlatIndexes(); if ($indexes !== null) { - // phpcs:ignore Magento2.Performance.ForeachArrayMerge - $this->_indexes = array_merge($this->_indexes, $indexes); + $indexesPerAttribute[] = $indexes; } } + $this->_indexes = array_merge(...$indexesPerAttribute); } return $this->_indexes; }