Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[TwigBundle][FrameworkBundle] Fixed that Twig cache warmer is not being added as cache warmer #15034

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

Closed
wants to merge 3 commits into from

Conversation

denniscoorn
Copy link

Description

Since version 2.7 the Twig cache warmer is not being triggered during a app/console cache:warmup. The bug is introduced with commit 0d537c4 where the tag kernel.cache_warmer is removed from the service definition twig.cache_warmer and is added dynamically by the ExtensionPass.

The problem lies in the fact that the AddCacheWarmerPass of the FrameworkBundle has already been processed on the moment the ExtensionPass adds the tag to the twig.cache_warmer service. Therefore the twig.cache_warmer is not being picked up by the AddCacheWarmerPass and will not be used during an app/console cache:warmup.

To verify my hypothesis I made a small change in AppKernel and placed TwigBundleabove FrameworkBundle, to force a different processing order of compiler passes and that fixed the problem.

Steps to reproduce

  • Install a fresh copy of symfony symfony new test
  • Run app/console cache:warmup

Notice that the directory app/cache/dev/twig doesn't exists.

Solution

My suggested fix is small but effective and consists of adding the argument PassConfig::TYPE_OPTIMIZE to the addCompilerPass method call when adding the AddCacheWarmerPass to the container. This ensures that other bundles were able to add tags to there service definitions, regarding cache warmers, before the AddCacheWarmerPass is being called.

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #15982
License MIT
Doc PR -

…ng added as cache warmer

PassConfig::TYPE_OPTIMIZE argument added to 'addCompilerPass' method call when adding the AddCacheWarmerPass to the container
@fabpot
Copy link
Member

fabpot commented Jun 21, 2015

Can you add a test to avoid any future regression?

…ng added as cache warmer

Test added to avoid any future regression
@denniscoorn denniscoorn force-pushed the fix/twig-cache-warmer branch from 4af0aac to 19e8c29 Compare June 23, 2015 06:59
@denniscoorn
Copy link
Author

@fabpot Just added a test to avoid any future regression. I doubted a little bit about where I should add this test, because the fix is applied on the FrameworkBundle but the issue is closely related to the TwigBundle. Eventually I added a test to the TwigBundle because the main goal of the test is to ensure that the TemplateCacheCacheWarmer is being added to the cache warmer.

@denniscoorn denniscoorn reopened this Jun 25, 2015
…ng added as cache warmer

* Removed the previous committed TemplateCacheCacheWarmerTest from the TwigBundle
* Added a generic CacheWarmerTest to the FrameworkBundle
@denniscoorn
Copy link
Author

After investigating what causes the Travis CI build to fail I realized that the test I added is never going to pass when the TwigBundle tests are executed independently. Therefore I removed the previous committed TemplateCacheCacheWarmerTest from the TwigBundle and added a more generic CacheWarmerTest to the FrameworkBundle.

I hope I did everything as it should be. If not, please comment! :-)

@stof
Copy link
Member

stof commented Jun 25, 2015

there is an issue. This compiler pass should still run before the optimization passes, otherwise it could break optimizations (if you have circular references between your cache warmer and the CacheWarmerAggregate, they won't be detected anymore for instance because the circular reference will be created only after the validation. and there might be other broken cases). So -1 for the current patch.

IMO, what is needed is a way to set a priority between all compiler passes running before optimizations (because almost every compiler pass provided by bundles must actually run before optimizing the container)

@xabbuh
Copy link
Member

xabbuh commented Jun 26, 2015

What would actually happen when added the kernel.cache_warmer tag even if the templating service is not registered? Would that be an issue at all?

{
return true;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing newline

@fabpot
Copy link
Member

fabpot commented Oct 13, 2015

Closing for the reasons explained by @stof

@fabpot fabpot closed this Oct 13, 2015
fabpot added a commit that referenced this pull request Oct 17, 2015
This PR was merged into the 2.7 branch.

Discussion
----------

[TwigBundle] Fix Twig cache is not properly warmed

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #15982
| License       | MIT
| Doc PR        | -

Alternative to #15034

Commits
-------

e704ee4 [TwigBundle] Fix Twig cache is not properly warmed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants