Sha256: ce488a39a2906b57dfc36a0363c6aacae9220e496663969da1d5ae46967d1393

Contents?: true

Size: 1 KB

Versions: 33

Compression:

Stored size: 1 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 now 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 CACHE)
    EXPLAINED_SQLS = /\A\s*(with|select|update|delete|insert)\b/i
    def ignore_payload?(payload)
      payload[:exception] || IGNORED_PAYLOADS.include?(payload[:name]) || payload[:sql] !~ EXPLAINED_SQLS
    end

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

Version data entries

33 entries across 33 versions & 6 rubygems

Version Path
activerecord-4.2.11.3 lib/active_record/explain_subscriber.rb
activerecord-4.2.11.2 lib/active_record/explain_subscriber.rb
activerecord-4.2.11.1 lib/active_record/explain_subscriber.rb
activerecord-4.2.11 lib/active_record/explain_subscriber.rb
activerecord-4.2.10 lib/active_record/explain_subscriber.rb
activerecord-4.2.10.rc1 lib/active_record/explain_subscriber.rb
activerecord-4.2.9 lib/active_record/explain_subscriber.rb
activerecord-4.2.9.rc2 lib/active_record/explain_subscriber.rb
activerecord-4.2.9.rc1 lib/active_record/explain_subscriber.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activerecord-4.2.8/lib/active_record/explain_subscriber.rb
activerecord-4.2.8 lib/active_record/explain_subscriber.rb
activerecord-4.2.8.rc1 lib/active_record/explain_subscriber.rb
activerecord-4.2.7.1 lib/active_record/explain_subscriber.rb
activerecord-4.2.7 lib/active_record/explain_subscriber.rb
activerecord-4.2.7.rc1 lib/active_record/explain_subscriber.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/explain_subscriber.rb
activerecord-4.2.6 lib/active_record/explain_subscriber.rb
activerecord-4.2.6.rc1 lib/active_record/explain_subscriber.rb
activerecord-4.2.5.2 lib/active_record/explain_subscriber.rb
activerecord-4.2.5.1 lib/active_record/explain_subscriber.rb