diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2019-01-28 15:01:48 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2019-01-28 15:01:48 -0800 |
commit | bf9b7325f8814a4d90267e59697e5125f40a69c3 (patch) | |
tree | 37d890b5ffaa7f5a998bc8690c1966481d490151 | |
parent | 5bb1ad59b1fea70c82d0a3b654ef81a0a31c715c (diff) | |
download | rails-bf9b7325f8814a4d90267e59697e5125f40a69c3.tar.gz rails-bf9b7325f8814a4d90267e59697e5125f40a69c3.tar.bz2 rails-bf9b7325f8814a4d90267e59697e5125f40a69c3.zip |
Cache the digest path on the stack.
We can remove the ivar by caching the digest on the stack
-rw-r--r-- | actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb | 12 |
1 files changed, 5 insertions, 7 deletions
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 b2c4fe90f4..388f9e5e56 100644 --- a/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb +++ b/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb @@ -54,20 +54,18 @@ module ActionView def collection_by_cache_keys(view, template) seed = callable_cache_key? ? @options[:cached] : ->(i) { i } + digest_path = view.digest_path_from_virtual(template.virtual_path) + @collection.each_with_object({}) do |item, hash| - hash[expanded_cache_key(seed.call(item), view, template)] = item + hash[expanded_cache_key(seed.call(item), view, template, digest_path)] = item end end - def expanded_cache_key(key, view, template) - key = view.combined_fragment_cache_key(view.cache_fragment_name(key, virtual_path: template.virtual_path, digest_path: digest_path(view, template))) + def expanded_cache_key(key, view, template, digest_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(view, template) - @digest_path ||= view.digest_path_from_virtual(template.virtual_path) - end - # `order_by` is an enumerable object containing keys of the cache, # all keys are passed in whether found already or not. # |