aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/renderer
diff options
context:
space:
mode:
authorschneems <richard.schneeman+foo@gmail.com>2018-09-07 14:03:41 -0500
committerschneems <richard.schneeman+foo@gmail.com>2018-09-11 16:52:44 -0500
commit99d260298c3b70d70042c872841b5e81c938fd5b (patch)
tree849df22c67095a566f0270d4681701868a1e0d46 /actionview/lib/action_view/renderer
parent82ac7555ab69c1ae11360d2b9bd8dfd723a13485 (diff)
downloadrails-99d260298c3b70d70042c872841b5e81c938fd5b.tar.gz
rails-99d260298c3b70d70042c872841b5e81c938fd5b.tar.bz2
rails-99d260298c3b70d70042c872841b5e81c938fd5b.zip
Move digest path calculation out of loop
On every iteration of generating a cache for a collection a “digest path” is calculated even though it’s exactly the same for every element. This PR exposes a method `digest_path_from_virtual` that returns back a “digest_path”. This can in turn be passed back into `cache_fragment_name`. This not only does less work, but it also (you guessed it) uses less memory. before: Total allocated: 762539 bytes (7035 objects) after: Total allocated: 743590 bytes (6621 objects) (762539 - 743590)/ 762539.0 # => 2.4% faster ⚡️⚡️
Diffstat (limited to 'actionview/lib/action_view/renderer')
-rw-r--r--actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb6
1 files changed, 5 insertions, 1 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 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