Skip to content

[TwigBundle] Refresh twig paths when resources change. #14262

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

aitboudad
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Fixed tickets ~
Tests pass? yes
License MIT

foreach ($container->getParameter('kernel.bundles') as $bundle => $class) {
if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/'.$bundle.'/views')) {
$this->addTwigPath($twigFilesystemLoaderDefinition, $dir, $bundle);
$dirs[] = $dir;
Copy link
Member

Choose a reason for hiding this comment

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

Why don't we call addResource() here directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just to avoid call $container->addResource(new DirectoryResource($dir)); in several places

Copy link
Member

Choose a reason for hiding this comment

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

why avoiding it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed 2 vs 1 :), seem there is not big difference but I still like the old way.

@aitboudad aitboudad force-pushed the twig_directory_resource branch from ac51644 to 2462bc2 Compare April 8, 2015 11:57
@xabbuh
Copy link
Member

xabbuh commented Apr 8, 2015

👍

@fabpot
Copy link
Member

fabpot commented May 16, 2015

Why do you consider this as a new feature? Looks like a bug to me, no?

@aitboudad
Copy link
Contributor Author

@fabpot I think so as it throw an exception when we remove an already registed path, you can merge it into 2.3 without problems

@fabpot
Copy link
Member

fabpot commented May 16, 2015

Thank you @aitboudad.

fabpot added a commit that referenced this pull request May 16, 2015
…tboudad)

This PR was submitted for the 2.7 branch but it was merged into the 2.3 branch instead (closes #14262).

Discussion
----------

[TwigBundle] Refresh twig paths when resources change.

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

Commits
-------

cafb0d7 [TwigBundle] Refresh twig paths when resources change.
@fabpot fabpot closed this May 16, 2015
@aitboudad aitboudad deleted the twig_directory_resource branch May 16, 2015 14:44
@chbruyand
Copy link
Contributor

Hello,

This commit has a huge (+900% on a simple login page) impact on performances when the resources are being tracked by the container.
Is this really worth the benefits it gives ?

In fact, I don't understand why the Resources/view directories are added to the tracked resources ?

Regards.

@stof
Copy link
Member

stof commented May 28, 2015

@chbruyand because we need to reconfigure twig when the directory does not exist anymore.

@aitboudad @fabpot I think we actually need a DirectoryExistenceResource here, which would check for freshness in a different way. We don't care about the modification date of the directory for these cases. And we care about a case not covered by the current implementation: adding new directories in a place not detected previously (which still requires to clear the cache manually in the current setup). And actually, many other places using DirectoryResource currently should actually use such DirectoryExistenceResource (translator configuration paths or DoctrineBundle mapping paths for instance)

@chbruyand does this have an impact on all page load or only the first time after the symfony update ? If it is only the first time, it might be becaus eyou compare a request rebuilding the cache with a request not rebuilding it.

@chbruyand
Copy link
Contributor

@stof this is on all requests being made, not only when building the container for the first time.

@mpdude
Copy link
Contributor

mpdude commented May 28, 2015

@stof Do I get you right that in this case the contents of the directory do not matter, just the fact that a particular directory does or does not exist with the resource being stale if that changes?

@reisba
Copy link

reisba commented May 28, 2015

I updated my dev-environment to symfony 2.3.29 which seems to contain this patch and it really seems to have a performance penalty in the figures that @chbruyand pointed out. What makes it worse is that the site I'm writing makes additional ajax requests to the symfony-backend after the initial page-load and each one of the seems to be impacted in the same way.

I don't know if there's issues with my environment configuration, but going from .28 to .29 really broke the performance for me in dev-environment and these changes seem to be at the bottom of it for me.

@chbruyand
Copy link
Contributor

@stof I was starting to work on a patch based on your thoughts. Using a FileResource instead of a DirectoryResource would ensure twig is reconfigured when directory is deleted (I think there is no need for a DirectoryExistenceResource there). If we really want to skip the modification time check in that case, I would argue in favour of a FileExistenceResource or an extra argument to the existing FileResource.

@stof
Copy link
Member

stof commented May 28, 2015

@chbruyand we would also need to have it reconfigured when the non-existent directory is added though

@stof
Copy link
Member

stof commented May 28, 2015

And yes, it can be named FileExistenceResource, working with both files and directories.

@chbruyand
Copy link
Contributor

@stof I made a pull request (see #14773), comments are welcome

fabpot added a commit that referenced this pull request May 29, 2015
…nge. (aitboudad)"

This reverts commit 4d40852, reversing
changes made to dd2fb85.
fabpot added a commit that referenced this pull request May 29, 2015
* 2.3:
  Revert "bug #14262 [TwigBundle] Refresh twig paths when resources change. (aitboudad)"
  InvalidResourceException file name
  [Validators] Remove forgotten space in a translation key [nl]
  [Validators] Correct translation key and content [nl]
  added missing CVE number
  bumped Symfony version to 2.3.30
  updated VERSION for 2.3.29
  update CONTRIBUTORS for 2.3.29
  updated CHANGELOG for 2.3.29
  [CS] [Console] StreamOuput : fix loose comparison
  [DependencyInjection] Avoid unnecessary calls to strtolower()

Conflicts:
	src/Symfony/Component/Console/Output/StreamOutput.php
	src/Symfony/Component/HttpKernel/Kernel.php
fabpot added a commit that referenced this pull request May 29, 2015
* 2.6: (21 commits)
  Revert "bug #14262 [TwigBundle] Refresh twig paths when resources change. (aitboudad)"
  InvalidResourceException file name
  [Validators] Remove forgotten space in a translation key [nl]
  [Validators] Correct translation key and content [nl]
  bumped Symfony version to 2.6.9
  updated VERSION for 2.6.8
  updated CHANGELOG for 2.6.8
  added missing CVE number
  bumped Symfony version to 2.3.30
  updated VERSION for 2.3.29
  update CONTRIBUTORS for 2.3.29
  updated CHANGELOG for 2.3.29
  [Validators] Missing translations for arabic language.
  Code style
  fixed C
  [HttpKernel][Bundle] Check extension implements ExtensionInterface
  [DebugBundle] Fix config XSD
  [CS] [Console] StreamOuput : fix loose comparison
  [Framework][router commands] fixed failing test.
  [HttpKernel] Do not call the FragmentListener if _controller is already defined
  ...

Conflicts:
	src/Symfony/Component/HttpKernel/Kernel.php
	src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php
fabpot added a commit that referenced this pull request Jun 5, 2015
…ted (chbruyand)

This PR was squashed before being merged into the 2.8 branch (closes #14781).

Discussion
----------

[TwigBundle] Reconfigure twig paths when they are updated

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #14771, #14768, #14262, #14778
| License       | MIT

Refresh twig paths upon creation and deletion. As we don't care neither about path's modification time nor path's content, a new Resource has been added in the Config Component.
Full discussion in #14778.

Commits
-------

3cbff05 [TwigBundle] Reconfigure twig paths when they are updated
thunderer pushed a commit to thunderer/symfony that referenced this pull request Jul 7, 2015
…ces change. (aitboudad)"

This reverts commit 4d40852, reversing
changes made to dd2fb85.
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.

7 participants