-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI] Use GlobResource for non-tracked directories #23870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DI] Use GlobResource for non-tracked directories #23870
Conversation
I think the existing logic is correct in its intent to track only for new and deleted files, but not for changes. |
Then I probably misunderstood the mechanics. Here's how to reproduce my issue: symfony --quiet demo test
cd test
# run symfony to warm up cache
bin/console --quiet about
# see container modification time
date -r var/cache/dev/appDevDebugProjectContainer.php
# this is to see later the difference in seconds
sleep 2
# create a twig file
touch app/Resources/views/test.html.twig
# run command again and I expect here the container to be not recompiled
bin/console --quiet about
# it actually recompiles, because the modification time is now different
date -r var/cache/dev/appDevDebugProjectContainer.php This happens because of this call in TwigExtension which creates a Am I right that TwigBundle keeps track of all bundle directories to recompile container in case these directories appear or get removed? The actual problem is that dx becomes worse when you are waiting for n seconds after just changing a template... |
With current code there's no possibility to prevent directory tracking even by doing |
@nicolas-grekas , I've checked, with my changes new and deleted files are still tracked correctly. |
@vudaltsov the problem with your patch is that removing the |
@vudaltsov can you try this? --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php
+++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php
@@ -407,9 +407,13 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
return $exists;
}
- if ($trackContents && is_dir($path)) {
- $this->addResource(new DirectoryResource($path, is_string($trackContents) ? $trackContents : null));
- } elseif ($trackContents || is_dir($path)) {
+ if (is_dir($path)) {
+ if ($trackContents) {
+ $this->addResource(new DirectoryResource($path, is_string($trackContents) ? $trackContents : null));
+ } else {
+ $this->addResource(new GlobResource($path, '/*', false));
+ }
+ } elseif ($trackContents) {
$this->addResource(new FileResource($path));
} If it works, you can take the patch for your PR (and add a test case if possible.) |
@nicolas-grekas, this makes things better. Now editing existing templates doesn't make the container recompile. New templates still do. Which makes sense because Is it possible to improve it even more? As @jvasseur pointed out, we only need to track for directory's existence in case of TwigExtension. I'll try to experiment a little with this next week. |
8d0a48b
to
e9ea24f
Compare
e9ea24f
to
048eb18
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vudaltsov I fixed resource tracking for TwigBundle to be a straight file existence check.
@nicolas-grekas , awesome news! Thank you. I din't have time to look at this yet. |
Thank you @vudaltsov. |
This PR was merged into the 3.3 branch. Discussion ---------- [DI] Use GlobResource for non-tracked directories | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a I noticed that some of my excluded directories are still tracked by the container and changes to files inside them make it recompile. This brought me to the `$trackContents || is_dir($path)` line introduced in #21505. Commits ------- 048eb18 [DI] Use GlobResource for non-tracked directories
I noticed that some of my excluded directories are still tracked by the container and changes to files inside them make it recompile. This brought me to the
$trackContents || is_dir($path)
line introduced in #21505.