Class: ActiveRecord::Explainer::Subscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/activerecord/explainer/subscriber.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#sql(event) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/activerecord/explainer/subscriber.rb', line 6

def sql(event)
  payload = event.payload
  return if ignore_payload?(payload) || !ActiveRecord::Base.connection.supports_explain?

  # Save `affected_rows` and restore after issuing EXPLAIN query because
  # the query will resets `affected_rows` to 0.
  original_affectet_rows = affected_rows
  debug exec_explain(sql: payload[:sql], binds: payload[:binds])
ensure
  affectet_rows = original_affectet_rows
end