Skip to content

Commit 139cef7

Browse files
minor #28200 [Config] Fix slow service discovery for large excluded directories (gonzalovilaseca)
This PR was squashed before being merged into the 4.2-dev branch (closes #28200). Discussion ---------- [Config] Fix slow service discovery for large excluded directories | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | no | Fixed tickets | #26736 | License | MIT | Doc PR | Not sure if this is a bug fix or not, is more an improvement. Please for all detail follow the conversation here: symfony/symfony#26736 Commits ------- fa731e53e9 [Config] Fix slow service discovery for large excluded directories
2 parents 3c8c8f7 + d366097 commit 139cef7

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

Loader/FileLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private function findClasses($namespace, $pattern, array $excludePatterns)
109109
$excludePrefix = null;
110110
$excludePatterns = $parameterBag->unescapeValue($parameterBag->resolveValue($excludePatterns));
111111
foreach ($excludePatterns as $excludePattern) {
112-
foreach ($this->glob($excludePattern, true, $resource) as $path => $info) {
112+
foreach ($this->glob($excludePattern, true, $resource, false, true) as $path => $info) {
113113
if (null === $excludePrefix) {
114114
$excludePrefix = $resource->getPrefix();
115115
}
@@ -123,7 +123,7 @@ private function findClasses($namespace, $pattern, array $excludePatterns)
123123
$classes = array();
124124
$extRegexp = '/\\.php$/';
125125
$prefixLen = null;
126-
foreach ($this->glob($pattern, true, $resource) as $path => $info) {
126+
foreach ($this->glob($pattern, true, $resource, false, false, $excludePaths) as $path => $info) {
127127
if (null === $prefixLen) {
128128
$prefixLen = \strlen($resource->getPrefix());
129129

Tests/Loader/XmlFileLoaderTest.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,19 @@ public function testPrototype()
612612

613613
$fixturesDir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR;
614614
$this->assertTrue(false !== array_search(new FileResource($fixturesDir.'xml'.\DIRECTORY_SEPARATOR.'services_prototype.xml'), $resources));
615-
$this->assertTrue(false !== array_search(new GlobResource($fixturesDir.'Prototype', '/*', true), $resources));
615+
616+
$prototypeRealPath = \realpath(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'Prototype');
617+
$globResource = new GlobResource(
618+
$fixturesDir.'Prototype',
619+
'/*',
620+
true,
621+
false,
622+
array(
623+
str_replace(\DIRECTORY_SEPARATOR, '/', $prototypeRealPath.\DIRECTORY_SEPARATOR.'OtherDir') => true,
624+
str_replace(\DIRECTORY_SEPARATOR, '/', $prototypeRealPath.\DIRECTORY_SEPARATOR.'BadClasses') => true,
625+
)
626+
);
627+
$this->assertTrue(false !== array_search($globResource, $resources));
616628
$resources = array_map('strval', $resources);
617629
$this->assertContains('reflection.Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo', $resources);
618630
$this->assertContains('reflection.Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar', $resources);
@@ -632,7 +644,19 @@ public function testPrototypeExcludeWithArray()
632644

633645
$fixturesDir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR;
634646
$this->assertTrue(false !== array_search(new FileResource($fixturesDir.'xml'.\DIRECTORY_SEPARATOR.'services_prototype_array.xml'), $resources));
635-
$this->assertTrue(false !== array_search(new GlobResource($fixturesDir.'Prototype', '/*', true), $resources));
647+
648+
$prototypeRealPath = realpath(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'Prototype');
649+
$globResource = new GlobResource(
650+
$fixturesDir.'Prototype',
651+
'/*',
652+
true,
653+
false,
654+
array(
655+
str_replace(\DIRECTORY_SEPARATOR, '/', $prototypeRealPath.\DIRECTORY_SEPARATOR.'BadClasses') => true,
656+
str_replace(\DIRECTORY_SEPARATOR, '/', $prototypeRealPath.\DIRECTORY_SEPARATOR.'OtherDir') => true,
657+
)
658+
);
659+
$this->assertTrue(false !== array_search($globResource, $resources));
636660
$resources = array_map('strval', $resources);
637661
$this->assertContains('reflection.Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo', $resources);
638662
$this->assertContains('reflection.Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar', $resources);

Tests/Loader/YamlFileLoaderTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,18 @@ public function testPrototype()
365365

366366
$fixturesDir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR;
367367
$this->assertTrue(false !== array_search(new FileResource($fixturesDir.'yaml'.\DIRECTORY_SEPARATOR.'services_prototype.yml'), $resources));
368-
$this->assertTrue(false !== array_search(new GlobResource($fixturesDir.'Prototype', '', true), $resources));
368+
369+
$prototypeRealPath = \realpath(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'Prototype');
370+
$globResource = new GlobResource(
371+
$fixturesDir.'Prototype',
372+
'',
373+
true,
374+
false, array(
375+
str_replace(\DIRECTORY_SEPARATOR, '/', $prototypeRealPath.\DIRECTORY_SEPARATOR.'BadClasses') => true,
376+
str_replace(\DIRECTORY_SEPARATOR, '/', $prototypeRealPath.\DIRECTORY_SEPARATOR.'OtherDir') => true,
377+
)
378+
);
379+
$this->assertTrue(false !== array_search($globResource, $resources));
369380
$resources = array_map('strval', $resources);
370381
$this->assertContains('reflection.Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo', $resources);
371382
$this->assertContains('reflection.Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar', $resources);

0 commit comments

Comments
 (0)