Class: Gitlab::Analytics::CycleAnalytics::RecordsFetcher

Inherits:
Object
  • Object
show all
Includes:
StageQueryHelpers, CycleAnalytics::MetricsTables, Utils::StrongMemoize
Defined in:
lib/gitlab/analytics/cycle_analytics/records_fetcher.rb

Constant Summary collapse

MAX_RECORDS =
Gitlab::Analytics::CycleAnalytics::Aggregated::RecordsFetcher::MAX_RECORDS
MAPPINGS =
Gitlab::Analytics::CycleAnalytics::Aggregated::RecordsFetcher::MAPPINGS

Instance Method Summary collapse

Methods included from CycleAnalytics::MetricsTables

#build_table, #issue_metrics_table, #issue_table, #mr_closing_issues_table, #mr_diff_commits_table, #mr_diff_table, #mr_metrics_table, #mr_table, #projects_table, #routes_table, #user_table

Methods included from StageQueryHelpers

#duration, #end_event_timestamp_projection, #execute_query, #in_progress?, #order_by, #requires_grouping?, #round_duration_to_seconds, #zero_interval

Constructor Details

#initialize(stage:, query:, params: {}) ⇒ RecordsFetcher

Returns a new instance of RecordsFetcher.



16
17
18
19
20
21
22
23
24
# File 'lib/gitlab/analytics/cycle_analytics/records_fetcher.rb', line 16

def initialize(stage:, query:, params: {})
  @stage = stage
  @query = query
  @params = params
  @sort = params[:sort] || :end_event
  @direction = params[:direction] || :desc
  @page = params[:page] || 1
  @per_page = MAX_RECORDS
end

Instance Method Details

#serialized_recordsObject

rubocop: disable CodeReuse/ActiveRecord



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

def serialized_records
  strong_memoize(:serialized_records) do
    records = ordered_and_limited_query.select(*columns, *time_columns)

    yield records if block_given?
    records = preload_associations(records)

    records.map do |record|
      project = record.project
      attributes = record.attributes.merge({
        project_path: project.path,
        namespace_path: project.namespace.route.path,
        author: record.author
      })
      serializer.represent(attributes)
    end
  end
end