Skip to content

Commit

Permalink
Don't explain except normal CRUD sql.
Browse files Browse the repository at this point in the history
  • Loading branch information
kennyj committed May 30, 2012
1 parent f7ed0af commit 4a25742
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion activerecord/lib/active_record/explain_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ def call(*args)
# On the other hand, we want to monitor the performance of our real database
# queries, not the performance of the access to the query cache.
IGNORED_PAYLOADS = %w(SCHEMA EXPLAIN CACHE)
EXPLAINED_SQLS = /^\s*(select|update|delete|insert)/i
def ignore_payload?(payload)
payload[:exception] || IGNORED_PAYLOADS.include?(payload[:name])
payload[:exception] || IGNORED_PAYLOADS.include?(payload[:name]) || payload[:sql] !~ EXPLAINED_SQLS
end

ActiveSupport::Notifications.subscribe("sql.active_record", new)
Expand Down
9 changes: 8 additions & 1 deletion activerecord/test/cases/explain_subscriber_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ def test_collects_nothing_for_ignored_payloads
end
end

def test_collects_nothing_if_unexplained_sqls
with_queries([]) do |queries|
SUBSCRIBER.call(:name => 'SQL', :sql => 'SHOW max_identifier_length')
assert queries.empty?
end
end

def test_collects_pairs_of_queries_and_binds
sql = 'select 1 from users'
binds = [1, 2]
Expand All @@ -45,4 +52,4 @@ def with_queries(queries)
Thread.current[:available_queries_for_explain] = nil
end
end
end
end

0 comments on commit 4a25742

Please sign in to comment.