diff options
author | Richard Schneeman <richard.schneeman+no-recruiters@gmail.com> | 2018-09-11 17:30:09 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-11 17:30:09 -0500 |
commit | 9e2460393524556ac3aae7e84a0b077055ec1b4d (patch) | |
tree | 36a0df5bfa1b17963953aff6cc3be0724a7510dc | |
parent | 21b32bb2a8001240e3e2c42811e2777d0411837d (diff) | |
parent | 99d260298c3b70d70042c872841b5e81c938fd5b (diff) | |
download | rails-9e2460393524556ac3aae7e84a0b077055ec1b4d.tar.gz rails-9e2460393524556ac3aae7e84a0b077055ec1b4d.tar.bz2 rails-9e2460393524556ac3aae7e84a0b077055ec1b4d.zip |
Merge pull request #33821 from schneems/schneems/digester-no-array
Move digest path calculation out of loop
-rw-r--r-- | actionview/lib/action_view/helpers/cache_helper.rb | 26 | ||||
-rw-r--r-- | actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb | 6 |
2 files changed, 22 insertions, 10 deletions
diff --git a/actionview/lib/action_view/helpers/cache_helper.rb b/actionview/lib/action_view/helpers/cache_helper.rb index 15d187a9ec..b1a14250c3 100644 --- a/actionview/lib/action_view/helpers/cache_helper.rb +++ b/actionview/lib/action_view/helpers/cache_helper.rb @@ -208,27 +208,35 @@ module ActionView # # The digest will be generated using +virtual_path:+ if it is provided. # - def cache_fragment_name(name = {}, skip_digest: nil, virtual_path: nil) + def cache_fragment_name(name = {}, skip_digest: nil, virtual_path: nil, digest_path: nil) if skip_digest name else - fragment_name_with_digest(name, virtual_path) + fragment_name_with_digest(name, virtual_path, digest_path) + end + end + + def digest_path_from_virtual(virtual_path) # :nodoc: + digest = Digestor.digest(name: virtual_path, finder: lookup_context, dependencies: view_cache_dependencies) + + if digest.present? + "#{virtual_path}:#{digest}" + else + virtual_path end end private - def fragment_name_with_digest(name, virtual_path) + def fragment_name_with_digest(name, virtual_path, digest_path) virtual_path ||= @virtual_path - if virtual_path + if virtual_path || digest_path name = controller.url_for(name).split("://").last if name.is_a?(Hash) - if digest = Digestor.digest(name: virtual_path, finder: lookup_context, dependencies: view_cache_dependencies).presence - [ "#{virtual_path}:#{digest}", name ] - else - [ virtual_path, name ] - end + digest_path ||= digest_path_from_virtual(virtual_path) + + [ digest_path, name ] else name end diff --git a/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb b/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb index db52919e91..3c10e0452f 100644 --- a/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb +++ b/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb @@ -40,10 +40,14 @@ module ActionView end def expanded_cache_key(key) - key = @view.combined_fragment_cache_key(@view.cache_fragment_name(key, virtual_path: @template.virtual_path)) + key = @view.combined_fragment_cache_key(@view.cache_fragment_name(key, virtual_path: @template.virtual_path, digest_path: digest_path)) key.frozen? ? key.dup : key # #read_multi & #write may require mutability, Dalli 2.6.0. end + def digest_path + @digest_path ||= @view.digest_path_from_virtual(@template.virtual_path) + end + def fetch_or_cache_partial(cached_partials, order_by:) order_by.map do |cache_key| cached_partials.fetch(cache_key) do |