Module: Gitlab::Analytics::CycleAnalytics::StageQueryHelpers

Included in:
Median, RecordsFetcher
Defined in:
lib/gitlab/analytics/cycle_analytics/stage_query_helpers.rb

Instance Method Summary collapse

Instance Method Details

#durationObject


19
20
21
22
23
24
# File 'lib/gitlab/analytics/cycle_analytics/stage_query_helpers.rb', line 19

def duration
  Arel::Nodes::Subtraction.new(
    stage.end_event.timestamp_projection,
    stage.start_event.timestamp_projection
  )
end

#execute_query(query) ⇒ Object


7
8
9
# File 'lib/gitlab/analytics/cycle_analytics/stage_query_helpers.rb', line 7

def execute_query(query)
  ActiveRecord::Base.connection.execute(query.to_sql)
end

#order_by_end_event(query, extra_columns_to_select = [:id]) ⇒ Object

rubocop: disable CodeReuse/ActiveRecord


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/gitlab/analytics/cycle_analytics/stage_query_helpers.rb', line 27

def order_by_end_event(query, extra_columns_to_select = [:id])
  ordered_query = query.reorder(stage.end_event.timestamp_projection.desc)

  # When filtering for more than one label, postgres requires the columns in ORDER BY to be present in the GROUP BY clause
  if requires_grouping?
    column_list = [
      *extra_columns_to_select,
      *stage.end_event.column_list,
      *stage.start_event.column_list
    ]

    ordered_query = ordered_query.group(column_list)
  end

  ordered_query
end

#requires_grouping?Boolean

rubocop: enable CodeReuse/ActiveRecord

Returns:

  • (Boolean)

45
46
47
# File 'lib/gitlab/analytics/cycle_analytics/stage_query_helpers.rb', line 45

def requires_grouping?
  Array(params[:label_name]).size > 1
end

#round_duration_to_secondsObject


15
16
17
# File 'lib/gitlab/analytics/cycle_analytics/stage_query_helpers.rb', line 15

def round_duration_to_seconds
  Arel::Nodes::NamedFunction.new('ROUND', [Arel::Nodes::Extract.new(duration, :epoch)])
end

#zero_intervalObject


11
12
13
# File 'lib/gitlab/analytics/cycle_analytics/stage_query_helpers.rb', line 11

def zero_interval
  Arel::Nodes::NamedFunction.new('CAST', [Arel.sql("'0' AS INTERVAL")])
end