Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented query tracker to track queries via thread local.
- Loading branch information
Dmitry Ratnikov
committed
Jan 26, 2012
1 parent
8f397af
commit f56b654
Showing
2 changed files
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class ActiveRecord::QueryTracker | ||
def self.record_sql_event(event) | ||
sql_events << event | ||
end | ||
|
||
def self.sql_events | ||
Thread.current['active_record_sql_events'] ||= [] | ||
end | ||
|
||
def self.reset_sql_events | ||
sql_events.clear | ||
end | ||
|
||
def call(*args) | ||
self.class.record_sql_event ActiveSupport::Notifications::Event.new(*args) | ||
end | ||
end | ||
|
||
ActiveSupport::Notifications.notifier.subscribe 'sql.active_record', ActiveRecord::QueryTracker.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'active_record/query_tracker' |