Sha256: 18893515fd59e4076d7c982d99b5cb1d33941b061360e3a1fb7e98496459db99

Contents?: true

Size: 1.23 KB

Versions: 12

Compression:

Stored size: 1.23 KB

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 async_sql_runtime
      ActiveSupport::IsolatedExecutionState[:active_record_async_sql_runtime] ||= 0.0
    end

    def async_sql_runtime=(runtime)
      ActiveSupport::IsolatedExecutionState[:active_record_async_sql_runtime] = runtime
    end

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

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

  if payload[:async]
    ActiveRecord::RuntimeRegistry.async_sql_runtime += (runtime - payload[:lock_wait])
  end
  ActiveRecord::RuntimeRegistry.sql_runtime += runtime
end

Version data entries

12 entries across 12 versions & 4 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/runtime_registry.rb
activerecord-7.1.5.1 lib/active_record/runtime_registry.rb
activerecord-7.1.5 lib/active_record/runtime_registry.rb
activerecord-7.1.4.2 lib/active_record/runtime_registry.rb
activerecord-7.1.4.1 lib/active_record/runtime_registry.rb
activerecord-7.1.4 lib/active_record/runtime_registry.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/runtime_registry.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/activerecord-7.1.3.4/lib/active_record/runtime_registry.rb
activerecord-7.1.3.4 lib/active_record/runtime_registry.rb
activerecord-7.1.3.2 lib/active_record/runtime_registry.rb
activerecord-7.1.3.1 lib/active_record/runtime_registry.rb
activerecord-7.1.3 lib/active_record/runtime_registry.rb