aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view
diff options
context:
space:
mode:
Diffstat (limited to 'actionview/lib/action_view')
-rw-r--r--actionview/lib/action_view/helpers/cache_helper.rb8
-rw-r--r--actionview/lib/action_view/log_subscriber.rb19
-rw-r--r--actionview/lib/action_view/renderer/partial_renderer.rb32
3 files changed, 42 insertions, 17 deletions
diff --git a/actionview/lib/action_view/helpers/cache_helper.rb b/actionview/lib/action_view/helpers/cache_helper.rb
index 6c3092cc46..b598469d01 100644
--- a/actionview/lib/action_view/helpers/cache_helper.rb
+++ b/actionview/lib/action_view/helpers/cache_helper.rb
@@ -226,7 +226,13 @@ module ActionView
# TODO: Create an object that has caching read/write on it
def fragment_for(name = {}, options = nil, &block) #:nodoc:
- read_fragment_for(name, options) || write_fragment_for(name, options, &block)
+ if content = read_fragment_for(name, options)
+ @log_payload_for_partial_render[:cache_hit] = true if defined?(@log_payload_for_partial_render)
+ content
+ else
+ @log_payload_for_partial_render[:cache_hit] = false if defined?(@log_payload_for_partial_render)
+ write_fragment_for(name, options, &block)
+ end
end
def read_fragment_for(name, options) #:nodoc:
diff --git a/actionview/lib/action_view/log_subscriber.rb b/actionview/lib/action_view/log_subscriber.rb
index 34e1a35dc2..c9f308c2a2 100644
--- a/actionview/lib/action_view/log_subscriber.rb
+++ b/actionview/lib/action_view/log_subscriber.rb
@@ -19,7 +19,16 @@ module ActionView
message << " (#{event.duration.round(1)}ms)"
end
end
- alias :render_partial :render_template
+
+ def render_partial(event)
+ info do
+ message = " Rendered #{from_rails_root(event.payload[:identifier])}"
+ message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout]
+ message << " (#{event.duration.round(1)}ms)"
+ message << " #{cache_message(event.payload)}" if event.payload.key?(:cache_hit)
+ message
+ end
+ end
def render_collection(event)
identifier = event.payload[:identifier] || "templates"
@@ -63,6 +72,14 @@ module ActionView
end
end
+ def cache_message(payload)
+ if payload[:cache_hit]
+ "[cache hit]"
+ else
+ "[cache miss]"
+ end
+ end
+
private
def log_rendering_start(payload)
diff --git a/actionview/lib/action_view/renderer/partial_renderer.rb b/actionview/lib/action_view/renderer/partial_renderer.rb
index 1509726a37..92bd0ccf91 100644
--- a/actionview/lib/action_view/renderer/partial_renderer.rb
+++ b/actionview/lib/action_view/renderer/partial_renderer.rb
@@ -308,9 +308,7 @@ module ActionView
if @collection
render_collection
else
- instrument(:partial) do
- render_partial
- end
+ render_partial
end
end
@@ -331,22 +329,26 @@ module ActionView
end
def render_partial
- view, locals, block = @view, @locals, @block
- object, as = @object, @variable
+ instrument(:partial) do |payload|
+ view, locals, block = @view, @locals, @block
+ object, as = @object, @variable
- if !block && (layout = @options[:layout])
- layout = find_template(layout.to_s, @template_keys)
- end
+ view.instance_variable_set(:@log_payload_for_partial_render, payload)
- object = locals[as] if object.nil? # Respect object when object is false
- locals[as] = object if @has_object
+ if !block && (layout = @options[:layout])
+ layout = find_template(layout.to_s, @template_keys)
+ end
- content = @template.render(view, locals) do |*name|
- view._layout_for(*name, &block)
- end
+ object = locals[as] if object.nil? # Respect object when object is false
+ locals[as] = object if @has_object
- content = layout.render(view, locals){ content } if layout
- content
+ content = @template.render(view, locals) do |*name|
+ view._layout_for(*name, &block)
+ end
+
+ content = layout.render(view, locals){ content } if layout
+ content
+ end
end
# Sets up instance variables needed for rendering a partial. This method