Skip to content
This repository
Browse code

Don't try to EXPLAIN select_db calls

  • Loading branch information...
commit 1cc63e94dbe52a9cf01a71c1dc45ee18443f97dc 1 parent 04d2715
Daniel Schierbeck authored
2  activerecord/lib/active_record/explain_subscriber.rb
@@ -19,7 +19,7 @@ def finish(name, id, payload)
19 19
     # On the other hand, we want to monitor the performance of our real database
20 20
     # queries, not the performance of the access to the query cache.
21 21
     IGNORED_PAYLOADS = %w(SCHEMA EXPLAIN CACHE)
22  
-    EXPLAINED_SQLS = /\A\s*(select|update|delete|insert)/i
  22
+    EXPLAINED_SQLS = /\A\s*(select|update|delete|insert)\b/i
23 23
     def ignore_payload?(payload)
24 24
       payload[:exception] || IGNORED_PAYLOADS.include?(payload[:name]) || payload[:sql] !~ EXPLAINED_SQLS
25 25
     end
5  activerecord/test/cases/explain_subscriber_test.rb
@@ -43,6 +43,11 @@ def test_collects_nothing_if_the_statement_is_not_whitelisted
43 43
       assert queries.empty?
44 44
     end
45 45
 
  46
+    def test_collects_nothing_if_the_statement_is_only_partially_matched
  47
+      SUBSCRIBER.finish(nil, nil, name: 'SQL', sql: 'select_db yo_mama')
  48
+      assert queries.empty?
  49
+    end
  50
+
46 51
     def teardown
47 52
       ActiveRecord::ExplainRegistry.reset
48 53
     end

0 notes on commit 1cc63e9

Please sign in to comment.
Something went wrong with that request. Please try again.