Class: ActiveRecord::LogSubscriber
- Inherits:
-
Object
- Object
- ActiveRecord::LogSubscriber
- Defined in:
- lib/time_bandits/monkey_patches/active_record.rb
Constant Summary collapse
- IGNORE_PAYLOAD_NAMES =
["SCHEMA", "EXPLAIN"]
Class Method Summary collapse
- .call_count ⇒ Object
- .call_count=(value) ⇒ Object
- .query_cache_hits ⇒ Object
- .query_cache_hits=(value) ⇒ Object
- .reset_call_count ⇒ Object
- .reset_query_cache_hits ⇒ Object
- .reset_runtime ⇒ Object
- .runtime ⇒ Object
- .runtime=(value) ⇒ Object
Instance Method Summary collapse
Class Method Details
.call_count ⇒ Object
28 29 30 31 |
# File 'lib/time_bandits/monkey_patches/active_record.rb', line 28 def self.call_count Thread.current.thread_variable_get(:active_record_sql_call_count) || Thread.current.thread_variable_set(:active_record_sql_call_count, 0) end |
.call_count=(value) ⇒ Object
24 25 26 |
# File 'lib/time_bandits/monkey_patches/active_record.rb', line 24 def self.call_count=(value) Thread.current.thread_variable_set(:active_record_sql_call_count, value) end |
.query_cache_hits ⇒ Object
37 38 39 40 |
# File 'lib/time_bandits/monkey_patches/active_record.rb', line 37 def self.query_cache_hits Thread.current.thread_variable_get(:active_record_sql_query_cache_hits) || Thread.current.thread_variable_set(:active_record_sql_query_cache_hits, 0) end |
.query_cache_hits=(value) ⇒ Object
33 34 35 |
# File 'lib/time_bandits/monkey_patches/active_record.rb', line 33 def self.query_cache_hits=(value) Thread.current.thread_variable_set(:active_record_sql_query_cache_hits, value) end |
.reset_call_count ⇒ Object
42 43 44 45 46 |
# File 'lib/time_bandits/monkey_patches/active_record.rb', line 42 def self.reset_call_count calls = call_count self.call_count = 0 calls end |
.reset_query_cache_hits ⇒ Object
48 49 50 51 52 |
# File 'lib/time_bandits/monkey_patches/active_record.rb', line 48 def self.reset_query_cache_hits hits = query_cache_hits self.query_cache_hits = 0 hits end |
.reset_runtime ⇒ Object
13 14 15 |
# File 'lib/time_bandits/monkey_patches/active_record.rb', line 13 def self.reset_runtime ActiveRecord::RuntimeRegistry.reset end |
.runtime ⇒ Object
16 17 18 |
# File 'lib/time_bandits/monkey_patches/active_record.rb', line 16 def self.runtime ActiveRecord::RuntimeRegistry.sql_runtime end |
.runtime=(value) ⇒ Object
19 20 21 |
# File 'lib/time_bandits/monkey_patches/active_record.rb', line 19 def self.runtime=(value) ActiveRecord::RuntimeRegistry.sql_runtime = value end |
Instance Method Details
#sql(event) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/time_bandits/monkey_patches/active_record.rb', line 55 def sql(event) payload = event.payload self.class.runtime += event.duration self.class.call_count += 1 self.class.query_cache_hits += 1 if payload[:cached] || payload[:name] == "CACHE" return unless logger.debug? return if IGNORE_PAYLOAD_NAMES.include?(payload[:name]) log_sql_statement(payload, event) end |