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
Instance Method Summary collapse
Class Method Details
.call_count ⇒ Object
19 20 21 22 |
# File 'lib/time_bandits/monkey_patches/active_record.rb', line 19 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
15 16 17 |
# File 'lib/time_bandits/monkey_patches/active_record.rb', line 15 def self.call_count=(value) Thread.current.thread_variable_set(:active_record_sql_call_count, value) end |
.query_cache_hits ⇒ Object
28 29 30 31 |
# File 'lib/time_bandits/monkey_patches/active_record.rb', line 28 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
24 25 26 |
# File 'lib/time_bandits/monkey_patches/active_record.rb', line 24 def self.query_cache_hits=(value) Thread.current.thread_variable_set(:active_record_sql_query_cache_hits, value) end |
.reset_call_count ⇒ Object
33 34 35 36 37 |
# File 'lib/time_bandits/monkey_patches/active_record.rb', line 33 def self.reset_call_count calls = call_count self.call_count = 0 calls end |
.reset_query_cache_hits ⇒ Object
39 40 41 42 43 |
# File 'lib/time_bandits/monkey_patches/active_record.rb', line 39 def self.reset_query_cache_hits hits = query_cache_hits self.query_cache_hits = 0 hits end |
Instance Method Details
#render_bind(column, value) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/time_bandits/monkey_patches/active_record.rb', line 55 def render_bind(column, value) if column if column.type == :binary value = "<#{value.bytesize} bytes of binary data>" end [column.name, value] else [nil, value] end end |
#sql(event) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/time_bandits/monkey_patches/active_record.rb', line 70 def sql(event) self.class.runtime += event.duration self.class.call_count += 1 self.class.query_cache_hits += 1 if event.payload[:name] == "CACHE" return unless logger.debug? payload = event.payload return if IGNORE_PAYLOAD_NAMES.include?(payload[:name]) log_sql_statement(payload, event) end |