aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-01-11 15:14:52 +0100
committerJosé Valim <jose.valim@gmail.com>2010-01-11 15:14:52 +0100
commitc1239e6509d27f88db2fc59189fd9a95333283e1 (patch)
treec3283f8228b9c6bc8a518a66bb0eca2004519434 /activerecord/lib/active_record
parent0a8004efd2136247decfcce83801478ae805d29e (diff)
downloadrails-c1239e6509d27f88db2fc59189fd9a95333283e1.tar.gz
rails-c1239e6509d27f88db2fc59189fd9a95333283e1.tar.bz2
rails-c1239e6509d27f88db2fc59189fd9a95333283e1.zip
Send the connection in AR notifications to avoid checking out new connections in threads just for logging purposes.
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-xactiverecord/lib/active_record/connection_adapters/abstract_adapter.rb6
-rw-r--r--activerecord/lib/active_record/railtie.rb2
2 files changed, 5 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
index 5eedf448a4..1ad54e7584 100755
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -193,15 +193,17 @@ module ActiveRecord
def log_info(sql, name, ms)
if @logger && @logger.debug?
- name = '%s (%.1fms)' % [name || 'SQL', ms]
+ name = '%s (%.1fms)' % [name, ms]
@logger.debug(format_log_entry(name, sql.squeeze(' ')))
end
end
protected
def log(sql, name)
+ name ||= "SQL"
result = nil
- ActiveSupport::Notifications.instrument("active_record.sql", :sql => sql, :name => name) do
+ ActiveSupport::Notifications.instrument("active_record.sql",
+ :sql => sql, :name => name, :connection => self) do
@runtime += Benchmark.ms { result = yield }
end
result
diff --git a/activerecord/lib/active_record/railtie.rb b/activerecord/lib/active_record/railtie.rb
index 55008271b7..a07f33503d 100644
--- a/activerecord/lib/active_record/railtie.rb
+++ b/activerecord/lib/active_record/railtie.rb
@@ -63,7 +63,7 @@ module ActiveRecord
require 'active_support/notifications'
ActiveSupport::Notifications.subscribe("active_record.sql") do |name, before, after, instrumenter_id, payload|
- ActiveRecord::Base.connection.log_info(payload[:sql], payload[:name], (after - before) * 1000)
+ payload[:connection].log_info(payload[:sql], payload[:name], (after - before) * 1000)
end
end