Sha256: f3a671a705ec043893f7da9efc3fea749ceb659e5ad35f30b60acfdc8b9cb524

Contents?: true

Size: 699 Bytes

Versions: 21

Compression:

Stored size: 699 Bytes

Contents

require 'active_support/notifications'

module ActiveRecord
  class ExplainSubscriber # :nodoc:
    def call(*args)
      if queries = Thread.current[:available_queries_for_explain]
        payload = args.last
        queries << payload.values_at(:sql, :binds) unless ignore_payload?(payload)
      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.
    IGNORED_PAYLOADS = %w(SCHEMA EXPLAIN)
    def ignore_payload?(payload)
      payload[:exception] || IGNORED_PAYLOADS.include?(payload[:name])
    end

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

Version data entries

21 entries across 21 versions & 3 rubygems

Version Path
challah-0.6.1 vendor/bundle/gems/activerecord-3.2.1/lib/active_record/explain_subscriber.rb
challah-0.6.0 vendor/bundle/gems/activerecord-3.2.1/lib/active_record/explain_subscriber.rb
challah-0.5.4 vendor/bundle/gems/activerecord-3.2.1/lib/active_record/explain_subscriber.rb
challah-0.5.3 vendor/bundle/gems/activerecord-3.2.1/lib/active_record/explain_subscriber.rb
challah-0.5.2 vendor/bundle/gems/activerecord-3.2.1/lib/active_record/explain_subscriber.rb
challah-0.5.0 vendor/bundle/gems/activerecord-3.2.1/lib/active_record/explain_subscriber.rb
challah-0.4.1 vendor/bundle/gems/activerecord-3.2.1/lib/active_record/explain_subscriber.rb
challah-0.4.0 vendor/bundle/gems/activerecord-3.2.1/lib/active_record/explain_subscriber.rb
challah-0.3.5 vendor/bundle/gems/activerecord-3.2.1/lib/active_record/explain_subscriber.rb
challah-0.3.4 vendor/bundle/gems/activerecord-3.2.1/lib/active_record/explain_subscriber.rb
challah-0.3.3 vendor/bundle/gems/activerecord-3.2.1/lib/active_record/explain_subscriber.rb
challah-0.3.2 vendor/bundle/gems/activerecord-3.2.1/lib/active_record/explain_subscriber.rb
challah-0.3.1 vendor/bundle/gems/activerecord-3.2.1/lib/active_record/explain_subscriber.rb
challah-0.3.0 vendor/bundle/gems/activerecord-3.2.1/lib/active_record/explain_subscriber.rb
challah-0.2.1 vendor/bundle/gems/activerecord-3.2.1/lib/active_record/explain_subscriber.rb
challah-0.2.0 vendor/bundle/gems/activerecord-3.2.1/lib/active_record/explain_subscriber.rb
sskirby-activerecord-3.2.1 lib/active_record/explain_subscriber.rb
activerecord-3.2.1 lib/active_record/explain_subscriber.rb
activerecord-3.2.0 lib/active_record/explain_subscriber.rb
activerecord-3.2.0.rc2 lib/active_record/explain_subscriber.rb