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 =
20
MAPPINGS =
{
  Issue => {
    serializer_class: AnalyticsIssueSerializer,
    includes_for_query: { project: { namespace: [:route] }, author: [] },
    columns_for_select: %I[title iid id created_at author_id project_id]
  },
  MergeRequest => {
    serializer_class: AnalyticsMergeRequestSerializer,
    includes_for_query: { target_project: [:namespace], author: [] },
    columns_for_select: %I[title iid id created_at author_id state_id target_project_id]
  }
}.freeze

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, #execute_query, #order_by_end_event, #requires_grouping?, #round_duration_to_seconds, #zero_interval

Methods included from Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

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

Returns a new instance of RecordsFetcher.


28
29
30
31
32
# File 'lib/gitlab/analytics/cycle_analytics/records_fetcher.rb', line 28

def initialize(stage:, query:, params: {})
  @stage = stage
  @query = query
  @params = params
end

Instance Method Details

#serialized_recordsObject


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/gitlab/analytics/cycle_analytics/records_fetcher.rb', line 34

def serialized_records
  strong_memoize(:serialized_records) do
    # special case (legacy): 'Test' and 'Staging' stages should show Ci::Build records
    if default_test_stage? || default_staging_stage?
      AnalyticsBuildSerializer.new.represent(ci_build_records.map { |e| e['build'] })
    else
      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
end