123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::StructuredEventSubscriber

Do not use. This class is for internal use only.

Constant Summary

Class Attribute Summary

::ActiveSupport::StructuredEventSubscriber - Inherited

::ActiveSupport::Subscriber - Inherited

.namespace, .notifier, .subscriber,
.event_method_names

::Method names for the ::String patterns attached on this class, frozen and replaced on change so that it can be read concurrently and from other Ractors.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

::ActiveSupport::StructuredEventSubscriber - Inherited

#call,
#emit_debug_event

Like emit_event, but only emits when the event reporter is in debug mode.

#emit_event

Emit a structured event via Rails.event.notify.

#emitting?

Whether any event reporter subscriber would currently consume an event with the given name.

#silenced?, #handle_event_error

::ActiveSupport::Subscriber - Inherited

Constructor Details

This class inherits a constructor from ActiveSupport::StructuredEventSubscriber

Instance Method Details

#filter(name, value) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/structured_event_subscriber.rb', line 67

def filter(name, value)
  ActiveRecord::Base.inspection_filter.filter_param(name, value)
end

#render_bind(attr, value, i) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/structured_event_subscriber.rb', line 56

def render_bind(attr, value, i)
  if attr.is_a?(ActiveModel::Attribute)
    if attr.type.binary? && attr.value
      value = "<#{attr.value_for_database.to_s.bytesize} bytes of binary data>"
    end
    [attr.name, value]
  else
    ["$#{i + 1}", value]
  end
end

#sql(event)

[ GitHub ]

  
# File 'activerecord/lib/active_record/structured_event_subscriber.rb', line 21

def sql(event)
  payload = event.payload

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

  binds = nil

  if payload[:binds]&.any?
    casted_params = type_casted_binds(payload[:type_casted_binds])

    binds = []
    payload[:binds].each_with_index do |attr, i|
      attribute_name = attr.name if attr.is_a?(ActiveModel::Attribute)
      filtered_params = filter(attribute_name, casted_params[i])
      binds << render_bind(attr, filtered_params, i)
    end
  end

  emit_debug_event("active_record.sql",
    async: payload[:async],
    name: payload[:name],
    sql: payload[:sql],
    cached: payload[:cached],
    lock_wait: payload[:lock_wait],
    binds: binds,
    duration_ms: event.duration.round(2),
  )
end

#strict_loading_violation(event)

[ GitHub ]

  
# File 'activerecord/lib/active_record/structured_event_subscriber.rb', line 9

def strict_loading_violation(event)
  owner = event.payload[:owner]
  reflection = event.payload[:reflection]

  emit_debug_event("active_record.strict_loading_violation",
    owner: owner.name,
    class: reflection.polymorphic? ? nil : reflection.klass.name,
    name: reflection.name,
  )
end

#type_casted_binds(casted_binds) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/structured_event_subscriber.rb', line 52

def type_casted_binds(casted_binds)
  casted_binds.respond_to?(:call) ? casted_binds.call : casted_binds
end