Class: ActiveRecord::ExplainRegistry::Subscriber
Do not use. This class is for internal use only.
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | activerecord/lib/active_record/explain_registry.rb |
Constant Summary
-
EXPLAINED_SQLS =
# File 'activerecord/lib/active_record/explain_registry.rb', line 50/\A\s*(\/\*.*\*\/)?\s*(with|select|update|delete|insert)\b/i -
IGNORED_PAYLOADS =
# File 'activerecord/lib/active_record/explain_registry.rb', line 49
SCHEMA queries cannot be EXPLAINed, also we do not want to run EXPLAIN on our own EXPLAINs no matter how loopingly beautiful that would be.
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.
%w(SCHEMA EXPLAIN).freeze
-
MUTEX =
# File 'activerecord/lib/active_record/explain_registry.rb', line 15Mutex.new
Class Method Summary
Instance Method Summary
Class Method Details
.ensure_subscribed
[ GitHub ]# File 'activerecord/lib/active_record/explain_registry.rb', line 19
def ensure_subscribed return if @subscribed MUTEX.synchronize do return if @subscribed ActiveSupport::Notifications.subscribe("sql.active_record", new) @subscribed = true end end
Instance Method Details
#finish(name, id, payload)
[ GitHub ]# File 'activerecord/lib/active_record/explain_registry.rb', line 34
def finish(name, id, payload) if ExplainRegistry.collect? && !ignore_payload?(payload) ExplainRegistry.queries << payload.values_at(:sql, :binds) end end
#ignore_payload?(payload) ⇒ Boolean
# File 'activerecord/lib/active_record/explain_registry.rb', line 51
def ignore_payload?(payload) payload[:exception] || payload[:cached] || IGNORED_PAYLOADS.include?(payload[:name]) || !payload[:sql].match?(EXPLAINED_SQLS) end
#silenced?(_name) ⇒ Boolean
# File 'activerecord/lib/active_record/explain_registry.rb', line 40
def silenced?(_name) !ExplainRegistry.collect? end
#start(name, id, payload)
[ GitHub ]# File 'activerecord/lib/active_record/explain_registry.rb', line 30
def start(name, id, payload) # unused end