8000 [TwigBundle] Allow to exclude files and directories on cache warmup by yceruto · Pull Request #34416 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[TwigBundle] Allow to exclude files and directories on cache warmup #34416

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 1 commit into from

Conversation

yceruto
Copy link
Member
@yceruto yceruto commented Nov 16, 2019
Q A
Branch? 5.1
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #34142
License MIT
Doc PR -

So you can put any file/directory (not related to Twig's templates) in templates/ dir and configure which files/directories can or cannot be warmed up, increasing the performance on 'cache:clear' (sometimes impossible).

Example of configurations:

twig:
    # include all *.twig files only
    cache_pattern_files: '*.twig'
    cache_pattern_files: '/\.twig$/' # same as above

    # include multiple files/extensions
    cache_pattern_files: ['*.twig', '*.svg'] # can be done in one regex too
    
    # exclude all *.png files only
    cache_pattern_files: '/.*(?<!\.png)$/'

    # exclude directory paths
    cache_exclude_paths: ['node_modules', '...'] # 'bundles' will always be excluded

Backward Compatibility

Unaffected! By default all files for all Twig's paths will be warmed up as well as the 'bundles' directory will be excluded even if it's not added to the cache_exclude_paths option by the user.

It's up to you to decide the structure of your template directories and which files/dirs should or shouldn't be cached.

Replacement of #34321
Also related to #28282

wdyt?

@yceruto yceruto added this to the next milestone Nov 16, 2019
@yceruto yceruto changed the title [TwigBundle] Allow to configure the files and directories to warmup on cache [TwigBundle] Allow to exclude files and directories on cache warmup Nov 16, 2019
@yceruto
Copy link
Member Author
yceruto commented Nov 16, 2019

Note that I'm using cache_pattern_files option for both purposes (include/exclude files), but we could separate it into two options cache_include_files and cache_exclude_files if you think it's more clear, calling to $finder->names() and $finder->notNames() methods respectively.

@fabpot
Copy link
Member
fabpot commented Nov 17, 2019

I'm always very skeptical when we add new settings and when they are global.

The templates/ directory is, well, for templates only. If people store something else, that's their responsibility, not ours. I'm 👎 for anything that allow people to store everything under the templates directory.

@m-vo
Copy link
Contributor
m-vo commented Nov 17, 2019

But what's with things like this?

<h1 class="logo">{{ include('@Twig/images/symfony-logo.svg') }} Symfony Exception</h1>

In a bare Symfony 4 installation with only twig installed I already get 28 templates and 64 'other' files including php templates and images.

Details: list of loaded templates during cache warmup
"base.html.twig"
"@Framework/FormTable/hidden_row.html.php"
"@Framework/FormTable/button_row.html.php"
"@Framework/FormTable/form_widget_compound.html.php"
"@Framework/FormTable/form_row.html.php"
"@Framework/Form/form_rows.html.php"
"@Framework/Form/color_widget.html.php"
"@Framework/Form/integer_widget.html.php"
"@Framework/Form/form_widget_simple.html.php"
"@Framework/Form/button_widget.html.php"
"@Framework/Form/repeated_row.html.php"
"@Framework/Form/button_attributes.html.php"
"@Framework/Form/hidden_widget.html.php"
"@Framework/Form/money_widget.html.php"
"@Framework/Form/form_start.html.php"
"@Framework/Form/datetime_widget.html.php"
"@Framework/Form/form_rest.html.php"
"@Framework/Form/reset_widget.html.php"
"@Framework/Form/form_errors.html.php"
"@Framework/Form/form_enctype.html.php"
"@Framework/Form/form.html.php"
"@Framework/Form/form_end.html.php"
"@Framework/Form/widget_container_attributes.html.php"
"@Framework/Form/search_widget.html.php"
"@Framework/Form/widget_attributes.html.php"
"@Framework/Form/choice_attributes.html.php"
"@Framework/Form/hidden_row.html.php"
"@Framework/Form/email_widget.html.php"
"@Framework/Form/choice_widget_options.html.php"
"@Framework/Form/checkbox_widget.html.php"
"@Framework/Form/choice_widget.html.php"
"@Framework/Form/range_widget.html.php"
"@Framework/Form/attributes.html.php"
"@Framework/Form/url_widget.html.php"
"@Framework/Form/button_row.html.php"
"@Framework/Form/form_widget.html.php"
"@Framework/Form/textarea_widget.html.php"
"@Framework/Form/radio_widget.html.php"
"@Framework/Form/tel_widget.html.php"
"@Framework/Form/choice_options.html.php"
"@Framework/Form/collection_widget.html.php"
"@Framework/Form/form_help.html.php"
"@Framework/Form/choice_widget_expanded.html.php"
"@Framework/Form/button_label.html.php"
"@Framework/Form/submit_widget.html.php"
"@Framework/Form/date_widget.html.php"
"@Framework/Form/number_widget.html.php"
"@Framework/Form/form_label.html.php"
"@Framework/Form/percent_widget.html.php"
"@Framework/Form/container_attributes.html.php"
"@Framework/Form/choice_widget_collapsed.html.php"
"@Framework/Form/time_widget.html.php"
"@Framework/Form/form_widget_compound.html.php"
"@Framework/Form/form_row.html.php"
"@Framework/Form/password_widget.html.php"
"@Twig/base_js.html.twig"
"@Twig/Exception/exception_full.html.twig"
"@Twig/Exception/exception.css.twig"
"@Twig/Exception/error.html.twig"
"@Twig/Exception/traces_text.html.twig"
"@Twig/Exception/error.js.twig"
"@Twig/Exception/error.txt.twig"
"@Twig/Exception/exception.html.twig"
"@Twig/Exception/trace.txt.twig"
"@Twig/Exception/traces.html.twig"
"@Twig/Exception/exception.json.twig"
"@Twig/Exception/trace.html.twig"
"@Twig/Exception/exception.atom.twig"
"@Twig/Exception/traces.txt.twig"
"@Twig/Exception/exception.rdf.twig"
"@Twig/Exception/exception.js.twig"
"@Twig/Exception/exception.txt.twig"
"@Twig/Exception/error.css.twig"
"@Twig/Exception/exception.xml.twig"
"@Twig/Exception/error.atom.twig"
"@Twig/Exception/traces.xml.twig"
"@Twig/Exception/error.json.twig"
"@Twig/Exception/logs.html.twig"
"@Twig/Exception/error.rdf.twig"
"@Twig/Exception/error.xml.twig"
"@Twig/exception.css.twig"
"@Twig/layout.html.twig"
"@Twig/images/icon-minus-square.svg"
"@Twig/images/favicon.png.base64"
"@Twig/images/icon-plus-square.svg"
"@Twig/images/symfony-ghost.svg"
"@Twig/images/icon-book.svg"
"@Twig/images/chevron-right.svg"
"@Twig/images/icon-plus-square-o.svg"
"@Twig/images/icon-minus-square-o.svg"
"@Twig/images/icon-support.svg"
"@Twig/images/symfony-logo.svg"

In this case filtering for .twig would work but that's not guaranteed as long as using other extensions is explicitly allowed/not deprecated. (also see #34142 (comment))

@yceruto
Copy link
Member Author
yceruto commented Nov 17, 2019

Fair enough 👍

@yceruto yceruto closed this Nov 17, 2019
@stof
Copy link
Member
stof commented Nov 28, 2019

@m-vo in this case, this file is a template (include includes templates)

@m-vo
Copy link
Contributor
m-vo commented Nov 28, 2019

You mean a template without any placeholders? That's an asset imho and that should not need to be parsed.

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.

[TwigBundle] TemplateCacheWarmer processes non-template files
6 participants
0