Skip to content

Commit

Permalink
Skip AR instantiation work if not debug.
Browse files Browse the repository at this point in the history
It's not that expensive but it runs on each query and we throw it out
at info level.
  • Loading branch information
jrafanie committed Nov 25, 2015
1 parent a7ad8ca commit e0a7565
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions config/initializers/instantiation_listener.rb
@@ -1,8 +1,10 @@
ActiveSupport::Notifications.subscribe('instantiation.active_record') do |name, start, finish, _id, payload|
elapsed = finish - start
name = payload[:class_name]
count = payload[:record_count]
logger = ActiveRecord::Base.logger
if logger.debug?
elapsed = finish - start
name = payload[:class_name]
count = payload[:record_count]

logger.debug(' %s Inst Including Associations (%.1fms - %drows)' % [name || 'SQL', (elapsed * 1000), count])
logger.debug(' %s Inst Including Associations (%.1fms - %drows)' % [name || 'SQL', (elapsed * 1000), count])
end
end

0 comments on commit e0a7565

Please sign in to comment.