Skip to content

Commit fb951c1

Browse files
ENGCOM-5932: Static Content Deploy - Optimize files scanning performance #24686
- Merge Pull Request #24686 from ven-com/magento2:2.3-optimize-files-scanning - Merged commits: 1. d562df9 2. 6ac4153 3. 2b33196 4. e720b68 5. 1cc75d4 6. 3e8b90c
2 parents db0dce6 + 3e8b90c commit fb951c1

File tree

1 file changed

+32
-30
lines changed
  • lib/internal/Magento/Framework/App/Utility

1 file changed

+32
-30
lines changed

lib/internal/Magento/Framework/App/Utility/Files.php

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,44 +24,20 @@
2424
*/
2525
class Files
2626
{
27-
/**
28-
* Include app code
29-
*/
3027
const INCLUDE_APP_CODE = 1;
3128

32-
/**
33-
* Include tests
34-
*/
3529
const INCLUDE_TESTS = 2;
3630

37-
/**
38-
* Include dev tools
39-
*/
4031
const INCLUDE_DEV_TOOLS = 4;
4132

42-
/**
43-
* Include templates
44-
*/
4533
const INCLUDE_TEMPLATES = 8;
4634

47-
/**
48-
* Include lib files
49-
*/
5035
const INCLUDE_LIBS = 16;
5136

52-
/**
53-
* Include pub code
54-
*/
5537
const INCLUDE_PUB_CODE = 32;
5638

57-
/**
58-
* Include non classes
59-
*/
6039
const INCLUDE_NON_CLASSES = 64;
6140

62-
/**
63-
* Include setup
64-
*/
6541
const INCLUDE_SETUP = 128;
6642

6743
/**
@@ -395,11 +371,11 @@ public function getMainConfigFiles($asDataSet = true)
395371
}
396372
$globPaths = [BP . '/app/etc/config.xml', BP . '/app/etc/*/config.xml'];
397373
$configXmlPaths = array_merge($globPaths, $configXmlPaths);
398-
$files = [];
374+
$files = [[]];
399375
foreach ($configXmlPaths as $xmlPath) {
400-
$files = array_merge($files, glob($xmlPath, GLOB_NOSORT));
376+
$files[] = glob($xmlPath, GLOB_NOSORT);
401377
}
402-
self::$_cache[$cacheKey] = $files;
378+
self::$_cache[$cacheKey] = array_merge(...$files);
403379
}
404380
if ($asDataSet) {
405381
return self::composeDataSets(self::$_cache[$cacheKey]);
@@ -679,6 +655,7 @@ private function collectModuleLayoutFiles(array $params, $location)
679655
}
680656
}
681657
} else {
658+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
682659
$files = array_merge($files, $moduleFiles);
683660
}
684661
}
@@ -713,8 +690,10 @@ private function collectThemeLayoutFiles(array $params, $location)
713690
);
714691

715692
if ($params['with_metainfo']) {
693+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
716694
$files = array_merge($this->parseThemeFiles($themeFiles, $currentThemePath, $theme));
717695
} else {
696+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
718697
$files = array_merge($files, $themeFiles);
719698
}
720699
}
@@ -925,14 +904,12 @@ public function getStaticPreProcessingFiles($filePattern = '*')
925904
$area = '*';
926905
$locale = '*';
927906
$result = [];
928-
$moduleWebPath = [];
929907
$moduleLocalePath = [];
930908
foreach ($this->componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleDir) {
931-
$moduleWebPath[] = $moduleDir . "/view/{$area}/web";
932909
$moduleLocalePath[] = $moduleDir . "/view/{$area}/web/i18n/{$locale}";
933910
}
934911

935-
$this->_accumulateFilesByPatterns($moduleWebPath, $filePattern, $result, '_parseModuleStatic');
912+
$this->accumulateStaticFiles($area, $filePattern, $result);
936913
$this->_accumulateFilesByPatterns($moduleLocalePath, $filePattern, $result, '_parseModuleLocaleStatic');
937914
$this->accumulateThemeStaticFiles($area, $locale, $filePattern, $result);
938915
self::$_cache[$key] = $result;
@@ -1043,6 +1020,8 @@ protected function _accumulateFilesByPatterns(array $patterns, $filePattern, arr
10431020
/**
10441021
* Parse meta-info of a static file in module
10451022
*
1023+
* @deprecated Replaced with method accumulateStaticFiles()
1024+
*
10461025
* @param string $file
10471026
* @return array
10481027
*/
@@ -1062,6 +1041,29 @@ protected function _parseModuleStatic($file)
10621041
return [];
10631042
}
10641043

1044+
/**
1045+
* Search static files from all modules by the specified pattern and accumulate meta-info
1046+
*
1047+
* @param string $area
1048+
* @param string $filePattern
1049+
* @param array $result
1050+
* @return void
1051+
*/
1052+
private function accumulateStaticFiles($area, $filePattern, array &$result)
1053+
{
1054+
foreach ($this->componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleName => $moduleDir) {
1055+
$moduleWebPath = $moduleDir . "/view/{$area}/web";
1056+
1057+
foreach (self::getFiles([$moduleWebPath], $filePattern) as $absolutePath) {
1058+
$localPath = substr($absolutePath, strlen($moduleDir) + 1);
1059+
if (preg_match('/^view\/([a-z]+)\/web\/(.+)$/i', $localPath, $matches) === 1) {
1060+
list(, $parsedArea, $parsedPath) = $matches;
1061+
$result[] = [$parsedArea, '', '', $moduleName, $parsedPath, $absolutePath];
1062+
}
1063+
}
1064+
}
1065+
}
1066+
10651067
/**
10661068
* Parse meta-info of a localized (translated) static file in module
10671069
*

0 commit comments

Comments
 (0)