Class: ActiveRecord::LogSubscriber
- Inherits:
-
Object
- Object
- ActiveRecord::LogSubscriber
- Defined in:
- lib/time_bandits/monkey_patches/active_record.rb
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
18 19 20 21 |
# File 'lib/time_bandits/monkey_patches/active_record.rb', line 18 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
14 15 16 |
# File 'lib/time_bandits/monkey_patches/active_record.rb', line 14 def self.call_count=(value) Thread.current.thread_variable_set(:active_record_sql_call_count, value) end |
.query_cache_hits ⇒ Object
27 28 29 30 |
# File 'lib/time_bandits/monkey_patches/active_record.rb', line 27 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
23 24 25 |
# File 'lib/time_bandits/monkey_patches/active_record.rb', line 23 def self.query_cache_hits=(value) Thread.current.thread_variable_set(:active_record_sql_query_cache_hits, value) end |
.reset_call_count ⇒ Object
32 33 34 35 36 |
# File 'lib/time_bandits/monkey_patches/active_record.rb', line 32 def self.reset_call_count calls = call_count self.call_count = 0 calls end |
.reset_query_cache_hits ⇒ Object
38 39 40 41 42 |
# File 'lib/time_bandits/monkey_patches/active_record.rb', line 38 def self.reset_query_cache_hits hits = query_cache_hits self.query_cache_hits = 0 hits end |
Instance Method Details
#sql(event) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/time_bandits/monkey_patches/active_record.rb', line 44 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 'SCHEMA' == payload[:name] name = '%s (%.1fms)' % [payload[:name], event.duration] sql = payload[:sql].squeeze(' ') binds = nil unless (payload[:binds] || []).empty? binds = " " + payload[:binds].map { |col,v| [col.name, v] }.inspect end if odd? name = color(name, CYAN, true) sql = color(sql, nil, true) else name = color(name, MAGENTA, true) end debug " #{name} #{sql}#{binds}" end |