diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-02-07 14:35:00 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-02-07 14:35:11 -0800 |
commit | 1193709cd693099488353c20f2c7fadcf9cd6d05 (patch) | |
tree | 91448e9985ba69ad09e7c106659445bd449d9fa3 /activerecord | |
parent | 9f773d66b5c52510ff5fdd27238e1763d29bcb91 (diff) | |
download | rails-1193709cd693099488353c20f2c7fadcf9cd6d05.tar.gz rails-1193709cd693099488353c20f2c7fadcf9cd6d05.tar.bz2 rails-1193709cd693099488353c20f2c7fadcf9cd6d05.zip |
removing some freedom patches. use notification system to count sql queries
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/test/cases/helper.rb | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/activerecord/test/cases/helper.rb b/activerecord/test/cases/helper.rb index 97bb631d2d..499b30b4e8 100644 --- a/activerecord/test/cases/helper.rb +++ b/activerecord/test/cases/helper.rb @@ -49,28 +49,29 @@ ensure ActiveRecord::Base.default_timezone = old_zone end -ActiveRecord::Base.connection.class.class_eval do - IGNORED_SQL = [/^PRAGMA (?!(table_info))/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/, /^SAVEPOINT/, /^ROLLBACK TO SAVEPOINT/, /^RELEASE SAVEPOINT/] +module ActiveRecord + class SQLCounter + IGNORED_SQL = [/^PRAGMA (?!(table_info))/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/, /^SAVEPOINT/, /^ROLLBACK TO SAVEPOINT/, /^RELEASE SAVEPOINT/] - # FIXME: this needs to be refactored so specific database can add their own - # ignored SQL. This ignored SQL is for Oracle. - IGNORED_SQL.concat [/^select .*nextval/i, /^SAVEPOINT/, /^ROLLBACK TO/, /^\s*select .* from ((all|user)_tab_columns|(all|user)_triggers|(all|user)_constraints)/im] + # FIXME: this needs to be refactored so specific database can add their own + # ignored SQL. This ignored SQL is for Oracle. + IGNORED_SQL.concat [/^select .*nextval/i, /^SAVEPOINT/, /^ROLLBACK TO/, /^\s*select .* from ((all|user)_tab_columns|(all|user)_triggers|(all|user)_constraints)/im] - def execute_with_query_record(sql, name = nil, &block) - $queries_executed ||= [] - $queries_executed << sql unless IGNORED_SQL.any? { |r| sql =~ r } - execute_without_query_record(sql, name, &block) - end + def initialize + $queries_executed = [] + end - alias_method_chain :execute, :query_record + def call(name, start, finish, message_id, values) + sql = values[:sql] - def exec_query_with_query_record(sql, name = nil, binds = [], &block) - $queries_executed ||= [] - $queries_executed << sql unless IGNORED_SQL.any? { |r| sql =~ r } - exec_query_without_query_record(sql, name, binds, &block) + # FIXME: this seems bad. we should probably have a better way to indicate + # the query was cached + unless 'CACHE' == values[:name] + $queries_executed << sql unless IGNORED_SQL.any? { |r| sql =~ r } + end + end end - - alias_method_chain :exec_query, :query_record + ActiveSupport::Notifications.subscribe('sql.active_record', SQLCounter.new) end ActiveRecord::Base.connection.class.class_eval { |