From 07da5aebb165f824d540fac620d2374b7a3799bb Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 24 Aug 2016 15:12:52 -0700 Subject: Simplify cache hit logging CacheHelper is mixed in to Helpers, Helpers is mixed in to AV::Base. This means we can count on instances of AV::Base to have the "cache hit" method on them, and we can stop setting an ivar for cache logging and just ask the view if it was a cache hit. --- actionview/lib/action_view/helpers/cache_helper.rb | 7 ++++--- actionview/lib/action_view/renderer/partial_renderer.rb | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'actionview/lib/action_view') diff --git a/actionview/lib/action_view/helpers/cache_helper.rb b/actionview/lib/action_view/helpers/cache_helper.rb index b598469d01..5258a01144 100644 --- a/actionview/lib/action_view/helpers/cache_helper.rb +++ b/actionview/lib/action_view/helpers/cache_helper.rb @@ -211,6 +211,8 @@ module ActionView end end + attr_reader :cache_hit # :nodoc: + private def fragment_name_with_digest(name, virtual_path) #:nodoc: @@ -224,13 +226,12 @@ module ActionView end end - # TODO: Create an object that has caching read/write on it def fragment_for(name = {}, options = nil, &block) #:nodoc: if content = read_fragment_for(name, options) - @log_payload_for_partial_render[:cache_hit] = true if defined?(@log_payload_for_partial_render) + @cache_hit = true content else - @log_payload_for_partial_render[:cache_hit] = false if defined?(@log_payload_for_partial_render) + @cache_hit = false write_fragment_for(name, options, &block) end end diff --git a/actionview/lib/action_view/renderer/partial_renderer.rb b/actionview/lib/action_view/renderer/partial_renderer.rb index 4314e1ff71..4b6aecd187 100644 --- a/actionview/lib/action_view/renderer/partial_renderer.rb +++ b/actionview/lib/action_view/renderer/partial_renderer.rb @@ -333,8 +333,6 @@ module ActionView view, locals, block = @view, @locals, @block object, as = @object, @variable - view.instance_variable_set(:@log_payload_for_partial_render, payload) - if !block && (layout = @options[:layout]) layout = find_template(layout.to_s, @template_keys) end @@ -347,6 +345,7 @@ module ActionView end content = layout.render(view, locals) { content } if layout + payload[:cache_hit] = view.cache_hit content end end -- cgit v1.2.3