diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2016-02-18 21:55:42 +0100 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2016-02-20 18:34:41 +0100 |
commit | b4700de1ce21599b500d43d8138184ee7ae81407 (patch) | |
tree | a01223eba163fcea56bb65039c9286444fd3bd23 /actionview/lib/action_view/log_subscriber.rb | |
parent | c4a46fa781d39f1b4607cb1613a1c67fa044ce54 (diff) | |
download | rails-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/log_subscriber.rb')
-rw-r--r-- | actionview/lib/action_view/log_subscriber.rb | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/actionview/lib/action_view/log_subscriber.rb b/actionview/lib/action_view/log_subscriber.rb index 9047dbdd85..aa38db2a3a 100644 --- a/actionview/lib/action_view/log_subscriber.rb +++ b/actionview/lib/action_view/log_subscriber.rb @@ -20,7 +20,15 @@ module ActionView end end alias :render_partial :render_template - alias :render_collection :render_template + + def render_collection(event) + identifier = event.payload[:identifier] || 'templates' + + info do + " Rendered collection of #{from_rails_root(identifier)}" \ + " #{render_count(event.payload)} (#{event.duration.round(1)}ms)" + end + end def logger ActionView::Base.logger @@ -38,6 +46,14 @@ module ActionView def rails_root @root ||= "#{Rails.root}/" end + + def render_count(payload) + if payload[:cache_hits] + "[#{payload[:cache_hits]} / #{payload[:count]} cache hits]" + else + "[#{payload[:count]} times]" + end + end end end |