Commit 7c109c57 authored by Tiago Botelho's avatar Tiago Botelho

Refactor CycleAnalytics base stage class and model

parent a7b3f11e
......@@ -31,7 +31,7 @@ class CycleAnalytics
end
def [](stage_name)
Gitlab::CycleAnalytics::Stage[stage_name].new(project: @project, options: @options)
Gitlab::CycleAnalytics::Stage[stage_name].new(projects: [@project], options: @options)
end
private
......
......@@ -6,7 +6,13 @@ class AnalyticsStageEntity < Grape::Entity
expose :legend
expose :description
expose :median, as: :value do |stage|
stage.median && !stage.median.zero? ? distance_of_time_in_words(stage.median) : nil
expose :medians, as: :values do |stage|
medians = stage.medians
unless medians.blank?
medians.each do |id, median|
medians[id] = distance_of_time_in_words(median)
end
end
end
end
......@@ -14,7 +14,7 @@ module Gitlab
def stage_query
query = mr_closing_issues_table.join(issue_table).on(issue_table[:id].eq(mr_closing_issues_table[:issue_id]))
.join(issue_metrics_table).on(issue_table[:id].eq(issue_metrics_table[:issue_id]))
.where(issue_table[:project_id].in(project_ids)) # rubocop:disable Gitlab/ModuleWithInstanceVariables
.where(issue_table[:project_id].in(Arel.sql(@projects.select(:id).to_sql))) # rubocop:disable Gitlab/ModuleWithInstanceVariables
.where(issue_table[:created_at].gteq(@options[:from])) # rubocop:disable Gitlab/ModuleWithInstanceVariables
# Load merge_requests
......@@ -26,10 +26,6 @@ module Gitlab
query
end
def project_ids
@projects.map(&:id)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment