Class: Praxis::Mapper::QueryStatistics
- Inherits:
-
Object
- Object
- Praxis::Mapper::QueryStatistics
- Defined in:
- lib/praxis-mapper/query_statistics.rb
Instance Method Summary collapse
-
#initialize(queries_by_model) ⇒ QueryStatistics
constructor
A new instance of QueryStatistics.
-
#sum_totals ⇒ Object
sums up statistics across all models and queries.
-
#sum_totals_by_model ⇒ Object
sums up statistics across all queries, indexed by model.
Constructor Details
#initialize(queries_by_model) ⇒ QueryStatistics
Returns a new instance of QueryStatistics.
5 6 7 |
# File 'lib/praxis-mapper/query_statistics.rb', line 5 def initialize(queries_by_model) @queries_by_model = queries_by_model end |
Instance Method Details
#sum_totals ⇒ Object
sums up statistics across all models and queries
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/praxis-mapper/query_statistics.rb', line 30 def sum_totals @sum_totals ||= begin totals = Hash.new(0) sum_totals_by_model.each do |_, model_totals| model_totals.each do |stat, value| totals[stat] += value end end totals end end |
#sum_totals_by_model ⇒ Object
sums up statistics across all queries, indexed by model
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/praxis-mapper/query_statistics.rb', line 10 def sum_totals_by_model @sum_totals_by_model ||= begin totals = Hash.new { |hash, key| hash[key] = Hash.new(0) } @queries_by_model.each do |model, queries| totals[model][:query_count] = queries.length queries.each do |query| query.statistics.each do |stat, value| totals[model][stat] += value end end totals[model][:datastore_interaction_time] = totals[model][:datastore_interaction_time] end totals end end |