From a3ebe51239c48a3b2bf28bf7a5d5782358b8f5a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Bajsarowicz?= Date: Thu, 6 Aug 2026 01:25:59 +0200 Subject: [PATCH] Build store configuration report in one array_merge call getReport() prepended each scope's rows to the report accumulated so far with array_merge, so every website and every store view copied the whole report built up to that point. The cost grows with the square of the number of scopes while the report itself grows linearly. Collect the per-scope reports and merge them once with argument unpacking. The collected list is reversed before merging, which keeps the existing row order - stores first, then websites, then the default scope - and the phpcs:ignore annotations for Magento2.Performance.ForeachArrayMerge are no longer needed. --- .../Model/StoreConfigurationProvider.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/app/code/Magento/Analytics/Model/StoreConfigurationProvider.php b/app/code/Magento/Analytics/Model/StoreConfigurationProvider.php index 8a81fc959a957..d5c468ed33bff 100644 --- a/app/code/Magento/Analytics/Model/StoreConfigurationProvider.php +++ b/app/code/Magento/Analytics/Model/StoreConfigurationProvider.php @@ -56,25 +56,21 @@ public function __construct( */ public function getReport() { - $configReport = $this->generateReportForScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0); + $reportsPerScope = [$this->generateReportForScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0)]; /** @var WebsiteInterface $website */ foreach ($this->storeManager->getWebsites() as $website) { - // phpcs:ignore Magento2.Performance.ForeachArrayMerge - $configReport = array_merge( - $this->generateReportForScope(ScopeInterface::SCOPE_WEBSITES, $website->getId()), - $configReport - ); + $reportsPerScope[] = $this->generateReportForScope(ScopeInterface::SCOPE_WEBSITES, $website->getId()); } /** @var StoreInterface $store */ foreach ($this->storeManager->getStores() as $store) { - // phpcs:ignore Magento2.Performance.ForeachArrayMerge - $configReport = array_merge( - $this->generateReportForScope(ScopeInterface::SCOPE_STORES, $store->getId()), - $configReport - ); + $reportsPerScope[] = $this->generateReportForScope(ScopeInterface::SCOPE_STORES, $store->getId()); } + + // Each scope used to be prepended to the report, so the most specific scope comes first + $configReport = array_merge(...array_reverse($reportsPerScope)); + return new \IteratorIterator(new \ArrayIterator($configReport)); }