Skip to content

Commit

Permalink
Implemented query tracker to track queries via thread local.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Ratnikov committed Jan 26, 2012
1 parent 8f397af commit f56b654
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/active_record/query_tracker.rb
@@ -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
1 change: 1 addition & 0 deletions lib/rails-xsrf-safety.rb
@@ -0,0 +1 @@
require 'active_record/query_tracker'

0 comments on commit f56b654

Please sign in to comment.