8000 bug #24824 [FrameworkBundle][Config] fix: do not add resource checker… · symfony/symfony@dc25f9a · GitHub
[go: up one dir, main page]

Skip to content

Commit dc25f9a

Browse files
committed
bug #24824 [FrameworkBundle][Config] fix: do not add resource checkers for no-debug (dmaicher)
This PR was merged into the 3.4 branch. Discussion ---------- [FrameworkBundle][Config] fix: do not add resource checkers for no-debug | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #24808 | License | MIT | Doc PR | - As mentioned within #24808 replacing the `ConfigCachePass` here 537c496...a442e37#diff-687bdbb38a4dc672ca2a79f23e764892L127 with a tagged iterator argument resulted in resource checkers being added even if debug=false. This resulted in a performance drop as on every request all the checkers have been checked. This restores the previous behavior and does not add any checkers if debug=false. Commits ------- 645f712 [FrameworkBundle][Config] fix: do not add resource checkers for debug=false
2 parents e973c24 + 645f712 commit dc25f9a

File tree

4 files changed

+28
-2
lines chan 10000 ged

4 files changed

+28
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

+5
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@ public function load(array $configs, ContainerBuilder $container)
361361
$container->registerForAutoconfiguration(ObjectInitializerInterface::class)
362362
->addTag('validator.initializer');
363363

364+
if (!$container->getParameter('kernel.debug')) {
365+
// remove tagged iterator argument for resource checkers
366+
$container->getDefinition('config_cache_factory')->setArguments(array());
367+
}
368+
364369
if (\PHP_VERSION_ID < 70000) {
365370
$this->addClassesToCompile(array(
366371
'Symfony\\Component\\Config\\ConfigCache',

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,17 @@ public function testCachePoolServices()
988988
$this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.def', 'cache.app', 11);
989989
}
990990

991+
public function testRemovesResourceCheckerConfigCacheFactoryArgumentOnlyIfNoDebug()
992+
{
993+
$container = $this->createContainer(array('kernel.debug' => true));
994+
(new FrameworkExtension())->load(array(), $container);
995+
$this->assertCount(1, $container->getDefinition('config_cache_factory')->getArguments());
996+
997+
$container = $this->createContainer(array('kernel.debug' => false));
998+
(new FrameworkExtension())->load(array(), $container);
999+
$this->assertEmpty($container->getDefinition('config_cache_factory')->getArguments());
1000+
}
1001+
9911002
protected function createContainer(array $data = array())
9921003
{
9931004
return new ContainerBuilder(new ParameterBag(array_merge(array(

src/Symfony/Component/Config/ResourceCheckerConfigCache.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ public function isFresh()
6868
return false;
6969
}
7070

71-
if (!$this->resourceCheckers) {
71+
if ($this->resourceCheckers instanceof \Traversable && !$this->resourceCheckers instanceof \Countable) {
72+
$this->resourceCheckers = iterator_to_array($this->resourceCheckers);
73+
}
74+
75+
if (!count($this->resourceCheckers)) {
7276
return true; // shortcut - if we don't have any checkers we don't need to bother with the meta file at all
7377
}
7478

src/Symfony/Component/Config/Tests/ResourceCheckerConfigCacheTest.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,20 @@ public function testCacheIsNotFreshIfEmpty()
5757
$this->assertFalse($cache->isFresh());
5858
}
5959

60-
public function testCacheIsFreshIfNocheckerProvided()
60+
public function testCacheIsFreshIfNoCheckerProvided()
6161
{
6262
/* For example in prod mode, you may choose not to run any checkers
6363
at all. In that case, the cache should always be considered fresh. */
6464
$cache = new ResourceCheckerConfigCache($this->cacheFile);
6565
$this->assertTrue($cache->isFresh());
6666
}
6767

68+
public function testCacheIsFreshIfEmptyCheckerIteratorProvided()
69+
{
70+
$cache = new ResourceCheckerConfigCache($this->cacheFile, new \ArrayIterator(array()));
71+
$this->assertTrue($cache->isFresh());
72+
}
73+
6874
public function testResourcesWithoutcheckersAreIgnoredAndConsideredFresh()
6975
{
7076
/* As in the previous test, but this time we have a resource. */

0 commit comments

Comments
 (0)
0