bug #23086 [FrameworkBundle] Fix perf issue in CacheClearCommand::warmup() (nicolas-grekas)
This PR was merged into the 2.7 branch.
Discussion
----------
[FrameworkBundle] Fix perf issue in CacheClearCommand::warmup()
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
On slow file systems (eg on Windows), I noticed that writing files without doing any changes just kills perf.
Limiting the depth also helps when the symfony/cache component is used (because it can store thousands of files in its cache pool directory structure, and iterating there is also a waste of *fs* time).
I choose the max depth by looking at where existing apps put their files and added one level more just in case.
Commits
-------
b58f060fda
[FrameworkBundle] Fix perf issue in CacheClearCommand::warmup()
This commit is contained in:
commit
0c17767dd5
|
@ -141,7 +141,7 @@ EOF
|
|||
$safeTempKernel = str_replace('\\', '\\\\', get_class($tempKernel));
|
||||
$realKernelFQN = get_class($realKernel);
|
||||
|
||||
foreach (Finder::create()->files()->name('*.meta')->in($warmupDir) as $file) {
|
||||
foreach (Finder::create()->files()->depth('<3')->name('*.meta')->in($warmupDir) as $file) {
|
||||
file_put_contents($file, preg_replace(
|
||||
'/(C\:\d+\:)"'.$safeTempKernel.'"/',
|
||||
sprintf('$1"%s"', $realKernelFQN),
|
||||
|
@ -153,14 +153,16 @@ EOF
|
|||
$search = array($warmupDir, str_replace('\\', '\\\\', $warmupDir));
|
||||
$replace = str_replace('\\', '/', $realCacheDir);
|
||||
foreach (Finder::create()->files()->in($warmupDir) as $file) {
|
||||
$content = str_replace($search, $replace, file_get_contents($file));
|
||||
file_put_contents($file, $content);
|
||||
$content = str_replace($search, $replace, file_get_contents($file), $count);
|
||||
if ($count) {
|
||||
file_put_contents($file, $content);
|
||||
}
|
||||
}
|
||||
|
||||
// fix references to container's class
|
||||
$tempContainerClass = get_class($tempKernel->getContainer());
|
||||
$realContainerClass = get_class($realKernel->getContainer());
|
||||
foreach (Finder::create()->files()->name($tempContainerClass.'*')->in($warmupDir) as $file) {
|
||||
foreach (Finder::create()->files()->depth('<2')->name($tempContainerClass.'*')->in($warmupDir) as $file) {
|
||||
$content = str_replace($tempContainerClass, $realContainerClass, file_get_contents($file));
|
||||
file_put_contents($file, $content);
|
||||
rename($file, str_replace(DIRECTORY_SEPARATOR.$tempContainerClass, DIRECTORY_SEPARATOR.$realContainerClass, $file));
|
||||
|
|
Reference in New Issue