Sha256: 9d443e90856bba3cef36a53ab6639b04b0c7a12f9c62010e47b5ba0e39ed99e8

Contents?: true

Size: 1.54 KB

Versions: 5

Compression:

Stored size: 1.54 KB

Contents

require "active_record/log_subscriber"

module ActiveRecord::Turntable
  module ActiveRecordExt
    module LogSubscriber
      # @note prepend to add shard name logging
      def sql(event)
        self.class.runtime += event.duration
        return unless logger.debug?

        payload = event.payload

        return if ActiveRecord::LogSubscriber::IGNORE_PAYLOAD_NAMES.include?(payload[:name])

        name  = "#{payload[:name]} (#{event.duration.round(1)}ms)"
        name  = "#{name} [Shard: #{payload[:turntable_shard_name]}]" if payload[:turntable_shard_name]
        name  = "CACHE #{name}" if payload[:cached]
        sql   = payload[:sql]
        binds = nil

        unless (payload[:binds] || []).empty?
          if Util.ar_version_equals_or_later?("5.0.3")
            casted_params = if Util.ar_version_satisfy?(">= 5.1.5") || Util.ar_version_satisfy?([">= 5.0.7", "< 5.1"])
                              type_casted_binds(payload[:type_casted_binds])
                            else
                              type_casted_binds(payload[:binds], payload[:type_casted_binds])
                            end
            binds = "  " + payload[:binds].zip(casted_params).map { |attr, value|
              render_bind(attr, value)
            }.inspect
          else
            binds = "  " + payload[:binds].map { |attr| render_bind(attr) }.inspect
          end
        end

        name = colorize_payload_name(name, payload[:name])
        sql  = color(sql, sql_color(sql), true)

        debug "  #{name}  #{sql}#{binds}"
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activerecord-turntable-4.4.1 lib/active_record/turntable/active_record_ext/log_subscriber.rb
activerecord-turntable-4.4.0 lib/active_record/turntable/active_record_ext/log_subscriber.rb
activerecord-turntable-4.3.0 lib/active_record/turntable/active_record_ext/log_subscriber.rb
activerecord-turntable-4.2.0 lib/active_record/turntable/active_record_ext/log_subscriber.rb
activerecord-turntable-4.1.0 lib/active_record/turntable/active_record_ext/log_subscriber.rb