Sha256: cbb46bd0626c46d6611b1fa485dba1c6d0dcc50aa26466661c759e19bd82d7a2

Contents?: true

Size: 1022 Bytes

Versions: 90

Compression:

Stored size: 1022 Bytes

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*(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

90 entries across 89 versions & 6 rubygems

Version Path
activerecord-4.1.16 lib/active_record/explain_subscriber.rb
activerecord-4.1.16.rc1 lib/active_record/explain_subscriber.rb
activerecord-4.1.15 lib/active_record/explain_subscriber.rb
activerecord-4.1.15.rc1 lib/active_record/explain_subscriber.rb
activerecord-4.1.14.2 lib/active_record/explain_subscriber.rb
activejob-lock-0.0.2 rails/activerecord/lib/active_record/explain_subscriber.rb
activerecord-4.1.14.1 lib/active_record/explain_subscriber.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/activerecord-4.1.13/lib/active_record/explain_subscriber.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/activerecord-4.1.13/lib/active_record/explain_subscriber.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/activerecord-4.1.13/lib/active_record/explain_subscriber.rb
activerecord-4.1.14 lib/active_record/explain_subscriber.rb
activerecord-4.1.14.rc2 lib/active_record/explain_subscriber.rb
activerecord-4.1.14.rc1 lib/active_record/explain_subscriber.rb
activerecord-4.1.13 lib/active_record/explain_subscriber.rb
activerecord-4.1.13.rc1 lib/active_record/explain_subscriber.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/activerecord-4.2.2/lib/active_record/explain_subscriber.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/activerecord-4.2.1/lib/active_record/explain_subscriber.rb
activerecord-4.1.12 lib/active_record/explain_subscriber.rb
activerecord-4.1.12.rc1 lib/active_record/explain_subscriber.rb
activerecord-4.2.2 lib/active_record/explain_subscriber.rb