Module: QueryOwl::QueryTracker
- Defined in:
- lib/query_owl/query_tracker.rb
Constant Summary collapse
- IGNORED_PATTERNS =
/^(SCHEMA|EXPLAIN|BEGIN|COMMIT|ROLLBACK|SAVEPOINT|RELEASE)/i
Class Method Summary collapse
Class Method Details
.queries ⇒ Object
23 24 25 |
# File 'lib/query_owl/query_tracker.rb', line 23 def queries Thread.current[:query_owl_queries] ||= [] end |
.record(event) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/query_owl/query_tracker.rb', line 10 def record(event) return unless tracking? return if event.payload[:name] == "SCHEMA" return if event.payload[:sql].to_s.match?(IGNORED_PATTERNS) queries << { sql: event.payload[:sql], duration_ms: event.duration.round(2), cached: event.payload[:cached], backtrace: filtered_backtrace } end |
.start! ⇒ Object
6 7 8 |
# File 'lib/query_owl/query_tracker.rb', line 6 def start! Thread.current[:query_owl_queries] = [] end |
.stop! ⇒ Object
27 28 29 30 31 |
# File 'lib/query_owl/query_tracker.rb', line 27 def stop! collected = queries.dup Thread.current[:query_owl_queries] = nil collected end |
.tracking? ⇒ Boolean
33 34 35 |
# File 'lib/query_owl/query_tracker.rb', line 33 def tracking? !Thread.current[:query_owl_queries].nil? end |