Class: Rack::DevInsight::Result::Sql::NormalizedAggregations

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/dev_insight/result/sql/normalized_aggregations.rb

Defined Under Namespace

Classes: NormalizedAggregation

Instance Method Summary collapse

Constructor Details

#initializeNormalizedAggregations

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

#attributesObject



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