Class: ActiveRecord::QueryCounter

Inherits:
ActiveSupport::Subscriber
  • Object
show all
Defined in:
lib/active_record/query_counter.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.currentObject



34
35
36
# File 'lib/active_record/query_counter.rb', line 34

def self.current
  @_current ||= new
end

Instance Method Details

#report_countsObject



48
49
50
# File 'lib/active_record/query_counter.rb', line 48

def report_counts
  LOG_TEMPLATE % counter.merge({ total: counter.values.sum })
end

#reset_counterObject



44
45
46
# File 'lib/active_record/query_counter.rb', line 44

def reset_counter
  counter.transform_values! { 0 }
end

#sql(event) ⇒ Object



38
39
40
41
42
# File 'lib/active_record/query_counter.rb', line 38

def sql(event)
  return if INGORED_QUERY_PREFIXES.detect { |s| event.payload[:sql].start_with?(s) }

  increment_counter(type: type_of_event(event))
end