Skip to content

Commit

Permalink
Send the connection in AR notifications to avoid checking out new con…
Browse files Browse the repository at this point in the history
…nections in threads just for logging purposes.
  • Loading branch information
josevalim committed Jan 11, 2010
1 parent 0a8004e commit c1239e6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Expand Up @@ -193,15 +193,17 @@ def current_savepoint_name

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
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/railtie.rb
Expand Up @@ -63,7 +63,7 @@ class Railtie < Rails::Railtie
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

Expand Down

0 comments on commit c1239e6

Please sign in to comment.