Class: ActiveRecord::StructuredEventSubscriber

Inherits:
ActiveSupport::StructuredEventSubscriber show all
Defined in:
activerecord/lib/active_record/structured_event_subscriber.rb

Overview

:nodoc:

Constant Summary collapse

IGNORE_PAYLOAD_NAMES =
["SCHEMA", "EXPLAIN"]

Constants inherited from ActiveSupport::StructuredEventSubscriber

ActiveSupport::StructuredEventSubscriber::DEBUG_CHECK

Instance Attribute Summary

Attributes inherited from ActiveSupport::StructuredEventSubscriber

#silenced_events

Attributes inherited from ActiveSupport::Subscriber

#patterns

Instance Method Summary collapse

Methods inherited from ActiveSupport::StructuredEventSubscriber

attach_to, #call, #emit_debug_event, #emit_event, #initialize, #silenced?

Methods inherited from ActiveSupport::Subscriber

attach_to, #call, detach_from, #initialize, method_added, subscribers

Constructor Details

This class inherits a constructor from ActiveSupport::StructuredEventSubscriber

Instance Method Details

#sql(event) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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 = if attr.respond_to?(:name)
        attr.name
      elsif attr.respond_to?(:[]) && attr[i].respond_to?(:name)
        attr[i].name
      else
        nil
      end

      filtered_params = filter(attribute_name, casted_params[i])

      binds << render_bind(attr, filtered_params)
    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) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# 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