From 7c109c575016eb0596e20180b334ca2955bd33e6 Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Fri, 9 Feb 2018 14:10:58 +0000 Subject: [PATCH] Refactor CycleAnalytics base stage class and model --- app/models/cycle_analytics.rb | 2 +- app/serializers/analytics_stage_entity.rb | 10 ++++++++-- lib/gitlab/cycle_analytics/base_query.rb | 6 +----- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/models/cycle_analytics.rb b/app/models/cycle_analytics.rb index a6191e569a7..c7f0e5f5cd8 100644 --- a/app/models/cycle_analytics.rb +++ b/app/models/cycle_analytics.rb @@ -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 diff --git a/app/serializers/analytics_stage_entity.rb b/app/serializers/analytics_stage_entity.rb index 564612202b5..ed1103b2064 100644 --- a/app/serializers/analytics_stage_entity.rb +++ b/app/serializers/analytics_stage_entity.rb @@ -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 diff --git a/lib/gitlab/cycle_analytics/base_query.rb b/lib/gitlab/cycle_analytics/base_query.rb index fee46fc0dda..05263dd30bc 100644 --- a/lib/gitlab/cycle_analytics/base_query.rb +++ b/lib/gitlab/cycle_analytics/base_query.rb @@ -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