Sha256: b38cb203efbc66f3328c7975653b479244536153b9ab7a88352c8dd538f86527

Contents?: true

Size: 957 Bytes

Versions: 26

Compression:

Stored size: 957 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)
    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

26 entries across 21 versions & 3 rubygems

Version Path
mdg-1.0.1 vendor/bundle/ruby/2.3.0/gems/activerecord-3.2.22.5/lib/active_record/explain_subscriber.rb
activerecord-3.2.22.5 lib/active_record/explain_subscriber.rb
activerecord-3.2.22.4 lib/active_record/explain_subscriber.rb
activerecord-3.2.22.3 lib/active_record/explain_subscriber.rb
activerecord-3.2.22.2 lib/active_record/explain_subscriber.rb
activerecord-3.2.22.1 lib/active_record/explain_subscriber.rb
activerecord-3.2.22 lib/active_record/explain_subscriber.rb
activerecord-3.2.21 lib/active_record/explain_subscriber.rb
apl-library-0.0.90 vendor/bundle/ruby/1.8/gems/activerecord-3.2.18/lib/active_record/explain_subscriber.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/activerecord-3.2.18/lib/active_record/explain_subscriber.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/explain_subscriber.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.8/gems/activerecord-3.2.18/lib/active_record/explain_subscriber.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/activerecord-3.2.18/lib/active_record/explain_subscriber.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/explain_subscriber.rb
activerecord-3.2.20 lib/active_record/explain_subscriber.rb
activerecord-3.2.19 lib/active_record/explain_subscriber.rb
activerecord-3.2.18 lib/active_record/explain_subscriber.rb
activerecord-3.2.17 lib/active_record/explain_subscriber.rb
activerecord-3.2.16 lib/active_record/explain_subscriber.rb
activerecord-3.2.15 lib/active_record/explain_subscriber.rb