diff options
author | Brian Durand <brian@embellishedvisions.com> | 2012-09-19 16:00:28 -0700 |
---|---|---|
committer | Brian Durand <brian@embellishedvisions.com> | 2012-09-19 16:00:28 -0700 |
commit | 19f0e37d7ae51c0a2b30f53127f68227ec55afec (patch) | |
tree | e70bc31e091a228054e0662b909319b02d65ab23 /activerecord | |
parent | 01059d7f7fcf2780c425895e4bdd5395edb6436b (diff) | |
download | rails-19f0e37d7ae51c0a2b30f53127f68227ec55afec.tar.gz rails-19f0e37d7ae51c0a2b30f53127f68227ec55afec.tar.bz2 rails-19f0e37d7ae51c0a2b30f53127f68227ec55afec.zip |
Optimize log subscribers to check if the log level is sufficient before performing an operations.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/log_subscriber.rb | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/log_subscriber.rb b/activerecord/lib/active_record/log_subscriber.rb index a25f2c7bca..ca79950049 100644 --- a/activerecord/lib/active_record/log_subscriber.rb +++ b/activerecord/lib/active_record/log_subscriber.rb @@ -1,11 +1,13 @@ module ActiveRecord class LogSubscriber < ActiveSupport::LogSubscriber + IGNORE_PAYLOAD_NAMES = ["SCHEMA", "EXPLAIN"] + def self.runtime=(value) - Thread.current["active_record_sql_runtime"] = value + Thread.current[:active_record_sql_runtime] = value end def self.runtime - Thread.current["active_record_sql_runtime"] ||= 0 + Thread.current[:active_record_sql_runtime] ||= 0 end def self.reset_runtime @@ -24,9 +26,9 @@ module ActiveRecord payload = event.payload - return if 'SCHEMA' == payload[:name] + return if IGNORE_PAYLOAD_NAMES.include?(payload[:name]) - name = '%s (%.1fms)' % [payload[:name], event.duration] + name = "#{payload[:name]} (#{event.duration.round(1)}ms)" sql = payload[:sql].squeeze(' ') binds = nil |