aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/log_subscriber.rb
diff options
context:
space:
mode:
authorBrian Durand <brian@embellishedvisions.com>2012-09-19 16:00:28 -0700
committerBrian Durand <brian@embellishedvisions.com>2012-09-30 09:47:24 -0700
commit37852726c93541aa1adc014cfb862659c9bcf349 (patch)
tree06cc8369010e8f3bd201cf54d9217e0223021248 /activerecord/lib/active_record/log_subscriber.rb
parent01059d7f7fcf2780c425895e4bdd5395edb6436b (diff)
downloadrails-37852726c93541aa1adc014cfb862659c9bcf349.tar.gz
rails-37852726c93541aa1adc014cfb862659c9bcf349.tar.bz2
rails-37852726c93541aa1adc014cfb862659c9bcf349.zip
Optimize log subscribers to check if the log level is sufficient before performing an operations.
Diffstat (limited to 'activerecord/lib/active_record/log_subscriber.rb')
-rw-r--r--activerecord/lib/active_record/log_subscriber.rb10
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