Sha256: 5ae06ca21432bbad6e51324d0ff30ee0b7a655af87c9977fa0430bb8ff4a9270

Contents?: true

Size: 1.04 KB

Versions: 20

Compression:

Stored size: 1.04 KB

Contents

require "active_support/notifications"
require "active_record/explain_registry"

module ActiveRecord
  class ExplainSubscriber # :nodoc:
    def start(name, id, payload)
      # unused
    end

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

    # 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.
    IGNORED_PAYLOADS = %w(SCHEMA EXPLAIN)
    EXPLAINED_SQLS = /\A\s*(with|select|update|delete|insert)\b/i
    def ignore_payload?(payload)
      payload[:exception] ||
        payload[:cached] ||
        IGNORED_PAYLOADS.include?(payload[:name]) ||
        payload[:sql] !~ EXPLAINED_SQLS
    end

    ActiveSupport::Notifications.subscribe("sql.active_record", new)
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
activerecord-5.1.7 lib/active_record/explain_subscriber.rb
activerecord-5.1.7.rc1 lib/active_record/explain_subscriber.rb
activerecord-5.1.6.2 lib/active_record/explain_subscriber.rb
activerecord-5.1.6.1 lib/active_record/explain_subscriber.rb
activerecord-5.1.6 lib/active_record/explain_subscriber.rb
activerecord-5.1.5 lib/active_record/explain_subscriber.rb
activerecord-5.1.5.rc1 lib/active_record/explain_subscriber.rb
activerecord-5.1.4 lib/active_record/explain_subscriber.rb
activerecord-5.1.4.rc1 lib/active_record/explain_subscriber.rb
activerecord-5.1.3 lib/active_record/explain_subscriber.rb
activerecord-5.1.3.rc3 lib/active_record/explain_subscriber.rb
activerecord-5.1.3.rc2 lib/active_record/explain_subscriber.rb
activerecord-5.1.3.rc1 lib/active_record/explain_subscriber.rb
activerecord-5.1.2 lib/active_record/explain_subscriber.rb
activerecord-5.1.2.rc1 lib/active_record/explain_subscriber.rb
activerecord-5.1.1 lib/active_record/explain_subscriber.rb
activerecord-5.1.0 lib/active_record/explain_subscriber.rb
activerecord-5.1.0.rc2 lib/active_record/explain_subscriber.rb
activerecord-5.1.0.rc1 lib/active_record/explain_subscriber.rb
activerecord-5.1.0.beta1 lib/active_record/explain_subscriber.rb