aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2011-12-04 13:53:26 -0800
committerXavier Noria <fxn@hashref.com>2011-12-04 13:53:26 -0800
commit4e74bd194beb6f51ee7c4bf06bfaab72d70f1c2c (patch)
treee73e3cef4b59e8e1a29052bf6a4de0788dbcd549 /activerecord
parent7f3ce35e1947c31233263a2cd48740646f5585b3 (diff)
downloadrails-4e74bd194beb6f51ee7c4bf06bfaab72d70f1c2c.tar.gz
rails-4e74bd194beb6f51ee7c4bf06bfaab72d70f1c2c.tar.bz2
rails-4e74bd194beb6f51ee7c4bf06bfaab72d70f1c2c.zip
moves some auto explain logic to the subscriber [José Valim & Xavier Noria]
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/explain.rb17
-rw-r--r--activerecord/lib/active_record/explain_subscriber.rb14
2 files changed, 12 insertions, 19 deletions
diff --git a/activerecord/lib/active_record/explain.rb b/activerecord/lib/active_record/explain.rb
index 6dff53d959..92b38d1b70 100644
--- a/activerecord/lib/active_record/explain.rb
+++ b/activerecord/lib/active_record/explain.rb
@@ -28,16 +28,6 @@ module ActiveRecord
end
end
- # This method receives payloads from the explain subscriber and is
- # responsible for collecting or ignoring them.
- def collect_queries_for_explain(payload) # :nodoc:
- if queries = Thread.current[:available_queries_for_explain]
- unless ignore_payload_for_explain?(payload)
- queries << payload.values_at(:sql, :binds)
- end
- end
- end
-
# Relation#explain needs to be able to collect the queries regardless of
# whether auto explain is enabled. This method serves that purpose.
def collecting_queries_for_explain # :nodoc:
@@ -49,13 +39,6 @@ module ActiveRecord
current[:available_queries_for_explain] = original
end
- # SCHEMA queries cannot be EXPLAINed, also we do not want to run EXPLAIN on
- # our own EXPLAINs now matter how loopingly beautiful that would be.
- SKIP_EXPLAIN_FOR = %w(SCHEMA EXPLAIN)
- def ignore_payload_for_explain?(payload) # :nodoc:
- payload[:exception] || SKIP_EXPLAIN_FOR.include?(payload[:name])
- end
-
# Makes the adapter execute EXPLAIN for the tuples of queries and bindings.
# Returns a formatted string ready to be logged.
def exec_explain(queries) # :nodoc:
diff --git a/activerecord/lib/active_record/explain_subscriber.rb b/activerecord/lib/active_record/explain_subscriber.rb
index aa5cf263a6..fc76410499 100644
--- a/activerecord/lib/active_record/explain_subscriber.rb
+++ b/activerecord/lib/active_record/explain_subscriber.rb
@@ -1,9 +1,19 @@
require 'active_support/notifications'
module ActiveRecord
- class ExplainSubscriber
+ class ExplainSubscriber # :nodoc:
def call(*args)
- ActiveRecord::Base.collect_queries_for_explain(args.last)
+ if queries = Thread.current[:available_queries_for_explain]
+ payload = args.last
+ queries << payload.values_at(:sql, :binds) unless ignore_payload?(payload)
+ end
+ end
+
+ # SCHEMA queries cannot be EXPLAINed, also we do not want to run EXPLAIN on
+ # our own EXPLAINs now matter how loopingly beautiful that would be.
+ IGNORED_PAYLOADS = %w(SCHEMA EXPLAIN)
+ def ignore_payload?(payload)
+ payload[:exception] || IGNORED_PAYLOADS.include?(payload[:name])
end
ActiveSupport::Notifications.subscribe("sql.active_record", new)