Sha256: b3d212fa6e3a8eacb888c44e9eb010da3e3c579ba3e772ba7186a0a82324324e

Contents?: true

Size: 832 Bytes

Versions: 6

Compression:

Stored size: 832 Bytes

Contents

# frozen_string_literal: true

module ActiveRecord
  # This is a thread locals registry for Active Record. For example:
  #
  #   ActiveRecord::RuntimeRegistry.sql_runtime
  #
  # returns the connection handler local to the current unit of execution (either thread of fiber).
  module RuntimeRegistry # :nodoc:
    extend self

    def sql_runtime
      ActiveSupport::IsolatedExecutionState[:active_record_sql_runtime] ||= 0.0
    end

    def sql_runtime=(runtime)
      ActiveSupport::IsolatedExecutionState[:active_record_sql_runtime] = runtime
    end

    def reset
      rt, self.sql_runtime = sql_runtime, 0.0
      rt
    end
  end
end

ActiveSupport::Notifications.monotonic_subscribe("sql.active_record") do |name, start, finish, id, payload|
  ActiveRecord::RuntimeRegistry.sql_runtime += (finish - start) * 1_000.0
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
activerecord-7.1.2 lib/active_record/runtime_registry.rb
activerecord-7.1.1 lib/active_record/runtime_registry.rb
activerecord-7.1.0 lib/active_record/runtime_registry.rb
activerecord-7.1.0.rc2 lib/active_record/runtime_registry.rb
activerecord-7.1.0.rc1 lib/active_record/runtime_registry.rb
activerecord-7.1.0.beta1 lib/active_record/runtime_registry.rb