Class: Rack::DevInsight::Result::Sql::NormalizedAggregations
- Inherits:
-
Object
- Object
- Rack::DevInsight::Result::Sql::NormalizedAggregations
- Defined in:
- lib/rack/dev_insight/result/sql/normalized_aggregations.rb
Defined Under Namespace
Classes: NormalizedAggregation
Instance Method Summary collapse
- #add(dialect_name, statement, duration, query_id) ⇒ Object
- #attributes ⇒ Object
-
#initialize ⇒ NormalizedAggregations
constructor
A new instance of NormalizedAggregations.
Constructor Details
#initialize ⇒ NormalizedAggregations
Returns a new instance of NormalizedAggregations.
10 11 12 13 |
# File 'lib/rack/dev_insight/result/sql/normalized_aggregations.rb', line 10 def initialize @id = 0 @cached_data = {} end |
Instance Method Details
#add(dialect_name, statement, duration, query_id) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rack/dev_insight/result/sql/normalized_aggregations.rb', line 15 def add(dialect_name, statement, duration, query_id) normalized_statements = Normalizer.normalize(dialect_name, statement) normalized_statement = normalized_statements.join('; ') data = @cached_data[normalized_statement] ||= NormalizedAggregation.new(@id += 1, normalized_statement, 0, 0, []) data.count += 1 data.duration += duration data.query_ids << query_id end |
#attributes ⇒ Object
26 27 28 29 30 31 |
# File 'lib/rack/dev_insight/result/sql/normalized_aggregations.rb', line 26 def attributes @cached_data.values.map do |data| data.duration = format('%.2f', data.duration).to_f data.to_h end end |