Module: ActiveRecord::RuntimeRegistry
- Extended by:
- RuntimeRegistry
- Included in:
- RuntimeRegistry
- Defined in:
- 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).
Defined Under Namespace
Classes: Stats
Instance Method Summary collapse
- #call(name, start, finish, id, payload) ⇒ Object
- #record(query_name, runtime, cached: false, async: false, lock_wait: nil) ⇒ Object
- #reset ⇒ Object
- #stats ⇒ Object
Instance Method Details
#call(name, start, finish, id, payload) ⇒ Object
32 33 34 35 36 37 38 39 |
# File '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) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File '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 ⇒ Object
59 60 61 |
# File 'lib/active_record/runtime_registry.rb', line 59 def reset stats.reset end |