Module: OccamsRecord::Measureable

Included in:
Query, RawQuery
Defined in:
lib/occams-record/measureable.rb

Overview

Measure the time each query takes. Useful for figuring out which query is the slow one when you’re doing a bunch of eager loads.

orders = OccamsRecord

.query(Order.all)
.eager_load(:customer)
...
.measure { |x|
  puts "Total time: #{x.total_time} sec"
  x.queries.each { |q|
    puts "Table: #{q.table_name} (#{q.time} sec)"
    puts q.sql
  }
}
.run

Instance Method Summary collapse

Instance Method Details

#measure {|OccamsRecord::Measurements| ... } ⇒ Object

Track the run time of each query, and the total run time of everything combined.

Yields:

Returns:

  • self



28
29
30
31
32
# File 'lib/occams-record/measureable.rb', line 28

def measure(&block)
  @measurements ||= []
  @measurement_results_block = block
  self
end