Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[TwigBundle] Pre-compile only *.twig files in cache warmup#45845
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
fabpot commentedMar 26, 2022
I'm not sure about this change, but this can only be merged in 6.1 anyway as this is a behavior change and not a bug fix (we always consider performance improvements as a new feature). |
GromNaN commentedMar 26, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Ok for 6.1. The question to answer before merging this PR is: is it expected to have twig templates that does not have the The alternative in my code is to decorate the iterator and filter each template name. class TemplateIteratorimplements \IteratorAggregate{publicfunction__construct(privateiterable$iterator) {}publicfunctiongetIterator():\Generator {foreach ($this->iteratoras$filename) {if (str_ends_with($filename,'.twig')) {yield$filename; } } }} And use a compiler pass to inject the decorator in the cache warmer. class TemplateIteratorPassimplements CompilerPassInterface{publicfunctionprocess(ContainerBuilder$container) {$warmer =$container->getDefinition('twig.template_cache_warmer');$iterator =$container->register(TemplateIterator::class, TemplateIterator::class)->addArgument($warmer->getArgument(1));$warmer->setArgument(1,$iterator); }} |
fabpot commentedMar 26, 2022
I think that this is indeed a great question. And the answer is: you can have templates with another extension. It's probably not widespread but nothing forbids it. |
GromNaN commentedMar 26, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I added an option to the twig:file_name_pattern:"*.twig"
|
GromNaN commentedMar 26, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Unfortunately, the deprecation is not reported in logs when running |
src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
GromNaN commentedMar 26, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
In Symfony WebProfilerBundle itself, all svg are included as templates with symfony/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/header.html.twig Line 3 in24304ad
symfony/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/time.html.twig Line 150 in24304ad
Zurb templates uses the symfony/src/Symfony/Bridge/Twig/Resources/views/Email/zurb_2/notification/body.html.twig Lines 6 to 7 in24304ad
See#45858 |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
yceruto commentedMar 27, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
GromNaN commentedMar 27, 2022
Thanks@yceruto. This proves this issue is common. Your PR was almost the same, with excluded directories in addition. @fabpotpresented the argument that |
fabpot commentedApr 1, 2022
Thank you@GromNaN. |
…colas-grekas)This PR was merged into the 6.1 branch.Discussion----------[TwigBridge] Make LintCommand::$namePatterns private| Q | A| ------------- | ---| Branch? | 6.1| Bug fix? | no| New feature? | no| Deprecations? | no| Tickets | -| License | MIT| Doc PR | -Dunno why this wasn't done in#45845. /cc `@GromNaN` any idea?Commits-------627a296 [TwigBridge] Make LintCommand::$namePatterns private
Uh oh!
There was an error while loading.Please reload this page.
In my project, the template directory contains all the frontend assets (CSS, JS and images), this is a choice to locate all component files in the same directories. But the asset files are compiled as if they were twig template, which is a waste of time and storage.
This patch limit warmup to*.twigfiles.This PR adds an option to restrict file pattern, for cache warmup and lint.
The filter on
*.twigfiles is already in thelint:twigcommand.Note: If a non-twig template is included in a template (ex: to inline CSS), the
source()function must be used ; the cache is not used in this case.Edit: Here is the documentationhttps://symfony.com/doc/current/reference/configuration/twig.html#file-name-pattern