Sha256: 21a525f03bdb9bd1dd326c9828695f642ced7300d69de8de131622bded47faf9

Contents?: true

Size: 861 Bytes

Versions: 55

Compression:

Stored size: 861 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.
    #
    # 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)
    def ignore_payload?(payload)
      payload[:exception] || IGNORED_PAYLOADS.include?(payload[:name])
    end

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

Version data entries

55 entries across 38 versions & 6 rubygems

Version Path
challah-0.6.2 vendor/bundle/gems/activerecord-3.2.3/lib/active_record/explain_subscriber.rb
challah-0.6.2 vendor/bundle/gems/activerecord-3.2.6/lib/active_record/explain_subscriber.rb
challah-0.6.2 vendor/bundle/gems/activerecord-3.2.5/lib/active_record/explain_subscriber.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/explain_subscriber.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/explain_subscriber.rb
initforthe-cookies-0.0.1 vendor/bundle/gems/activerecord-3.2.6/lib/active_record/explain_subscriber.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/explain_subscriber.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/explain_subscriber.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/explain_subscriber.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/explain_subscriber.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/explain_subscriber.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/explain_subscriber.rb
rails-uploader-0.0.4 vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/explain_subscriber.rb
rails-uploader-0.0.4 vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.6/lib/active_record/explain_subscriber.rb
activerecord-3.2.6 lib/active_record/explain_subscriber.rb
challah-0.6.1 vendor/bundle/gems/activerecord-3.2.3/lib/active_record/explain_subscriber.rb
challah-0.6.1 vendor/bundle/gems/activerecord-3.2.2/lib/active_record/explain_subscriber.rb
challah-0.6.1 vendor/bundle/gems/activerecord-3.2.5/lib/active_record/explain_subscriber.rb
activerecord-3.2.5 lib/active_record/explain_subscriber.rb
activerecord-3.2.4 lib/active_record/explain_subscriber.rb