Skip to content

[Performance] Fix array merge in loop to speed up static content deploy #22248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions app/code/Magento/Deploy/Package/Processor/PreProcessor/Css.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Deploy\Package\Processor\PreProcessor;

use Magento\Deploy\Console\DeployStaticOptions;
Expand Down Expand Up @@ -92,8 +93,7 @@ public function process(Package $package, array $options)
}

/**
* Checks if there are imports of CSS files or images within the given CSS file
* which exists in the current package
* Checks if there are imports of CSS files or images within the given CSS file which exists in the current package.
*
* @param PackageFile $parentFile
* @param Package $package
Expand Down Expand Up @@ -180,11 +180,13 @@ private function buildMap($packagePath, $filePath, $fullPath)
*/
private function collectFileMap($fileName)
{
$result = isset($this->map[$fileName]) ? $this->map[$fileName] : [];
$result = [$this->map[$fileName] ?? []];

foreach ($result as $path) {
$result = array_merge($result, $this->collectFileMap($path));
$result[] = $this->collectFileMap($path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An integration test is failing with provided changes: \Magento\Deploy\DeployTest
After the short investigation, we found that $path var can be the type of array and will break the check $this->map[$fileName].

}
return array_unique($result);

return array_unique(array_merge(...$result));
}

/**
Expand Down