123456789_123456789_123456789_123456789_123456789_

Module: ActiveRecord::RuntimeRegistry

Do not use. This module is for internal use only.
Relationships & Source Files
Namespace Children
Classes:
Defined in: activerecord/lib/active_record/runtime_registry.rb

Overview

This is a thread locals registry for Active Record. For example:

ActiveRecord::RuntimeRegistry.stats.sql_runtime

returns the connection handler local to the current unit of execution (either thread of fiber).

Instance Method Summary

Instance Method Details

#call(name, start, finish, id, payload)

[ GitHub ]

  
# File 'activerecord/lib/active_record/runtime_registry.rb', line 32

def call(name, start, finish, id, payload)
  record(
    payload[:name],
    (finish - start) * 1_000.0,
    async: payload[:async],
    lock_wait: payload[:lock_wait],
  )
end

#record(query_name, runtime, cached: false, async: false, lock_wait: nil)

[ GitHub ]

  
# File 'activerecord/lib/active_record/runtime_registry.rb', line 41

def record(query_name, runtime, cached: false, async: false, lock_wait: nil)
  stats = self.stats

  unless query_name == "TRANSACTION" || query_name == "SCHEMA"
    stats.queries_count += 1
    stats.cached_queries_count += 1 if cached
  end

  if async
    stats.async_sql_runtime += (runtime - lock_wait)
  end
  stats.sql_runtime += runtime
end

#reset

[ GitHub ]

  
# File 'activerecord/lib/active_record/runtime_registry.rb', line 59

def reset
  stats.reset
end

#stats

[ GitHub ]

  
# File 'activerecord/lib/active_record/runtime_registry.rb', line 55

def stats
  ActiveSupport::IsolatedExecutionState[:active_record_runtime] ||= Stats.new
end