Class: ActiveRecord::ExplainSubscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/explain_subscriber.rb

Overview

:nodoc:

Constant Summary collapse

IGNORED_PAYLOADS =

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)
EXPLAINED_SQLS =
/\A\s*(\/\*.*\*\/)?\s*(with|select|update|delete|insert)\b/i

Instance Method Summary collapse

Instance Method Details

#finish(name, id, payload) ⇒ Object



12
13
14
15
16
# File 'lib/active_record/explain_subscriber.rb', line 12

def finish(name, id, payload)
  if ExplainRegistry.collect? && !ignore_payload?(payload)
    ExplainRegistry.queries << payload.values_at(:sql, :binds)
  end
end

#ignore_payload?(payload) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
# File 'lib/active_record/explain_subscriber.rb', line 25

def ignore_payload?(payload)
  payload[:exception] ||
    payload[:cached] ||
    IGNORED_PAYLOADS.include?(payload[:name]) ||
    !payload[:sql].match?(EXPLAINED_SQLS)
end

#start(name, id, payload) ⇒ Object



8
9
10
# File 'lib/active_record/explain_subscriber.rb', line 8

def start(name, id, payload)
  # unused
end