aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/renderer/partial_renderer.rb
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2016-02-18 21:55:42 +0100
committerKasper Timm Hansen <kaspth@gmail.com>2016-02-20 18:34:41 +0100
commitb4700de1ce21599b500d43d8138184ee7ae81407 (patch)
treea01223eba163fcea56bb65039c9286444fd3bd23 /actionview/lib/action_view/renderer/partial_renderer.rb
parentc4a46fa781d39f1b4607cb1613a1c67fa044ce54 (diff)
downloadrails-b4700de1ce21599b500d43d8138184ee7ae81407.tar.gz
rails-b4700de1ce21599b500d43d8138184ee7ae81407.tar.bz2
rails-b4700de1ce21599b500d43d8138184ee7ae81407.zip
Instrument cached collection renders.
Augments the collection caching with some instrumentation that's logged. For collections that have been cached like: ```ruby <%= render partial: 'notifications/notification', collection: @notifications, cached: true %> ``` We'll output a line showing how many cache hits we had when rendering it: ``` Rendered collection of notifications/_notification.html.erb [0 / 100 cache hits] (3396.5ms) ```
Diffstat (limited to 'actionview/lib/action_view/renderer/partial_renderer.rb')
-rw-r--r--actionview/lib/action_view/renderer/partial_renderer.rb24
1 files changed, 12 insertions, 12 deletions
diff --git a/actionview/lib/action_view/renderer/partial_renderer.rb b/actionview/lib/action_view/renderer/partial_renderer.rb
index bdbf03191a..514804b08e 100644
--- a/actionview/lib/action_view/renderer/partial_renderer.rb
+++ b/actionview/lib/action_view/renderer/partial_renderer.rb
@@ -294,7 +294,7 @@ module ActionView
def render(context, options, block)
setup(context, options, block)
- identifier = (@template = find_partial) ? @template.identifier : @path
+ @template = find_partial
@lookup_context.rendered_format ||= begin
if @template && @template.formats.present?
@@ -305,11 +305,9 @@ module ActionView
end
if @collection
- instrument(:collection, :identifier => identifier || "collection", :count => @collection.size) do
- render_collection
- end
+ render_collection
else
- instrument(:partial, :identifier => identifier) do
+ instrument(:partial) do
render_partial
end
end
@@ -318,15 +316,17 @@ module ActionView
private
def render_collection
- return nil if @collection.blank?
+ instrument(:collection, count: @collection.size) do |payload|
+ return nil if @collection.blank?
- if @options.key?(:spacer_template)
- spacer = find_template(@options[:spacer_template], @locals.keys).render(@view, @locals)
- end
+ if @options.key?(:spacer_template)
+ spacer = find_template(@options[:spacer_template], @locals.keys).render(@view, @locals)
+ end
- cache_collection_render do
- @template ? collection_with_template : collection_without_template
- end.join(spacer).html_safe
+ cache_collection_render(payload) do
+ @template ? collection_with_template : collection_without_template
+ end.join(spacer).html_safe
+ end
end
def render_partial