Skip to content
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

Pass the template format to the digestor #35293

Merged
merged 3 commits into from Feb 19, 2019

Conversation

tenderlove
Copy link
Member

This commit passes the template format to the digestor in order to come
up with a key. Before this commit, the digestor would depend on the
side effect of the template renderer setting the rendered_format on the
lookup context. I would like to remove that mutation, so I've changed
this to pass the template format in to the digestor.

I've introduced a new instance variable that will be alive during a
template render. When the template is being rendered, it pushes the
current template on to a stack, setting @current_template to the
template currently being rendered. When the cache helper asks the
digestor for a key, it uses the format of the template currently on the
stack.

I removed the rendered_format= side effect in #35265 but the tests failed. It turns out that the digest caching code depends on that side effect, so this PR aims to remove the digest cache's dependency on the rendered_format setter. This PR fixes the Railties test in #35265

This commit passes the template format to the digestor in order to come
up with a key.  Before this commit, the digestor would depend on the
side effect of the template renderer setting the rendered_format on the
lookup context.  I would like to remove that mutation, so I've changed
this to pass the template format in to the digestor.

I've introduced a new instance variable that will be alive during a
template render.  When the template is being rendered, it pushes the
current template on to a stack, setting `@current_template` to the
template currently being rendered.  When the cache helper asks the
digestor for a key, it uses the format of the template currently on the
stack.
@javan
Copy link
Contributor

javan commented Feb 19, 2019

When the template is being rendered, it pushes the
current template on to a stack, setting @current_template to the
template currently being rendered. When the cache helper asks the
digestor for a key, it uses the format of the template currently on the
stack.

I've chased down a bunch of Digestor issues stemming from mixed format templates (e.g. a .js.erb template that renders .html.erb partials). Any chance this change could reintroduce some of them? Hard to tell if changes to the tests like these might be covering them up.

@tenderlove
Copy link
Member Author

tenderlove commented Feb 19, 2019

Hard to tell if changes to the tests like these might be covering them up.

I only removed those because they had no impact on the change. I can undo that change, but it has no impact on the tests. Since the digestor doesn't look at the renderd_format anymore, setting it to some value shouldn't have any impact.

Copy link
Contributor

@kaspth kaspth left a comment

Choose a reason for hiding this comment

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

I think this does do the same as the old code, but the flow is slightly clearer 👍

@@ -234,7 +234,7 @@ def fragment_name_with_digest(name, virtual_path, digest_path)
if virtual_path || digest_path
name = controller.url_for(name).split("://").last if name.is_a?(Hash)

digest_path ||= digest_path_from_virtual(virtual_path)
digest_path ||= digest_path_from_template(@current_template)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm taking this is the main difference? We've now captured the currently rendering template and can derive the format directly from it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, exactly

else
cache_key = [ name, finder.rendered_format, dependencies ].flatten.compact.join(".")
cache_key = [ name, format, dependencies ].flatten.compact.join(".")
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see how the old code would get a rendered_format here? Did you already consolidate rendered_format= on the finder/lookup_context or am I misremembering?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's pretty confusing, but the template renderer would set it on the lookup context. The partial renderer could do it too.

Copy link
Contributor

@kaspth kaspth Feb 19, 2019

Choose a reason for hiding this comment

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

Uhhh, right, they both set the same info but from slightly different vantage points. Got it, thanks 👍

@tenderlove tenderlove merged commit ff6b713 into master Feb 19, 2019
@tenderlove tenderlove deleted the remove-rendered-format-from-cache branch February 19, 2019 21:45
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.

None yet

4 participants