Skip to content

Commit 9157094

Browse files
bug symfony#61653 [Routing] Don't rebuild cache when controller action body changes (HypeMC)
This PR was submitted for the 7.4 branch but it was merged into the 7.3 branch instead. Discussion ---------- [Routing] Don't rebuild cache when controller action body changes | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT Currently, whenever the body of a controller action that uses attributes for routing is changed, the router cache is rebuilt. This can get a little annoying when you have many routes, as the rebuild time becomes noticeable, in my case, over 2 seconds. This PR switches to using `ReflectionClassResource` and `GlobResource` to prevent the cache from being rebuilt unnecessarily. I'm not sure how best to test this, or if there's even anything to test. Any suggestions would be appreciated. Commits ------- f2b9eac [Routing] Don't rebuild cache when controller action body changes
2 parents 189ed80 + f2b9eac commit 9157094

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/Symfony/Component/Routing/Loader/AttributeClassLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Component\Config\Loader\LoaderInterface;
1515
use Symfony\Component\Config\Loader\LoaderResolverInterface;
16-
use Symfony\Component\Config\Resource\FileResource;
16+
use Symfony\Component\Config\Resource\ReflectionClassResource;
1717
use Symfony\Component\Routing\Attribute\DeprecatedAlias;
1818
use Symfony\Component\Routing\Attribute\Route as RouteAttribute;
1919
use Symfony\Component\Routing\Exception\InvalidArgumentException;
@@ -104,7 +104,7 @@ public function load(mixed $class, ?string $type = null): RouteCollection
104104

105105
$globals = $this->getGlobals($class);
106106
$collection = new RouteCollection();
107-
$collection->addResource(new FileResource($class->getFileName()));
107+
$collection->addResource(new ReflectionClassResource($class));
108108
if ($globals['env'] && $this->env !== $globals['env']) {
109109
return $collection;
110110
}

src/Symfony/Component/Routing/Loader/AttributeDirectoryLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Component\Routing\Loader;
1313

14-
use Symfony\Component\Config\Resource\DirectoryResource;
14+
use Symfony\Component\Config\Resource\GlobResource;
1515
use Symfony\Component\Routing\RouteCollection;
1616

1717
/**
@@ -33,7 +33,7 @@ public function load(mixed $path, ?string $type = null): ?RouteCollection
3333
}
3434

3535
$collection = new RouteCollection();
36-
$collection->addResource(new DirectoryResource($dir, '/\.php$/'));
36+
$collection->addResource(new GlobResource($dir, '/*.php', true));
3737
$files = iterator_to_array(new \RecursiveIteratorIterator(
3838
new \RecursiveCallbackFilterIterator(
3939
new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS),

src/Symfony/Component/Routing/Loader/AttributeFileLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Component\Config\FileLocatorInterface;
1515
use Symfony\Component\Config\Loader\FileLoader;
16-
use Symfony\Component\Config\Resource\FileResource;
16+
use Symfony\Component\Config\Resource\ReflectionClassResource;
1717
use Symfony\Component\Routing\RouteCollection;
1818

1919
/**
@@ -52,7 +52,7 @@ public function load(mixed $file, ?string $type = null): ?RouteCollection
5252
return null;
5353
}
5454

55-
$collection->addResource(new FileResource($path));
55+
$collection->addResource(new ReflectionClassResource($refl));
5656
$collection->addCollection($this->loader->load($class, $type));
5757
}
5858

0 commit comments

Comments
 (0)