diff options
author | Tiago Botelho <tiagonbotelho@hotmail.com> | 2018-02-13 15:42:49 +0000 |
---|---|---|
committer | Tiago Botelho <tiagonbotelho@hotmail.com> | 2018-02-28 10:46:20 +0000 |
commit | 41bb23ae1d61f1e94749a288d822c93b430ee9c8 (patch) | |
tree | b223c9dc24759599e46c649300be32739775a975 /lib/gitlab/cycle_analytics | |
parent | 4fcbcce36475067f4d72ebe9371634e31073a497 (diff) | |
download | gitlab-ce-41bb23ae1d61f1e94749a288d822c93b430ee9c8.tar.gz |
Restore memoization to base query and add a batch base query method
Diffstat (limited to 'lib/gitlab/cycle_analytics')
-rw-r--r-- | lib/gitlab/cycle_analytics/base_query.rb | 10 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/base_stage.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/production_helper.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/test_stage.rb | 2 |
4 files changed, 8 insertions, 8 deletions
diff --git a/lib/gitlab/cycle_analytics/base_query.rb b/lib/gitlab/cycle_analytics/base_query.rb index ed050287a9d..cd3d19db28e 100644 --- a/lib/gitlab/cycle_analytics/base_query.rb +++ b/lib/gitlab/cycle_analytics/base_query.rb @@ -7,14 +7,15 @@ module Gitlab private - def base_query(project_ids = nil) - stage_query(project_ids) + def base_query + @base_query ||= stage_query([@project.id]) end - def stage_query(project_ids = nil) + def stage_query(project_ids) 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 || @project.id)) # rubocop:disable Gitlab/ModuleWithInstanceVariables + .project(issue_table[:project_id].as("project_id")) + .where(issue_table[:project_id].in(project_ids)) # rubocop:disable Gitlab/ModuleWithInstanceVariables .where(issue_table[:created_at].gteq(@options[:from])) # rubocop:disable Gitlab/ModuleWithInstanceVariables # Load merge_requests @@ -22,7 +23,6 @@ module Gitlab .on(mr_table[:id].eq(mr_closing_issues_table[:merge_request_id])) .join(mr_metrics_table) .on(mr_table[:id].eq(mr_metrics_table[:merge_request_id])) - .project(issue_table[:project_id].as("project_id")) query end diff --git a/lib/gitlab/cycle_analytics/base_stage.rb b/lib/gitlab/cycle_analytics/base_stage.rb index d7c98e41c63..45386fee622 100644 --- a/lib/gitlab/cycle_analytics/base_stage.rb +++ b/lib/gitlab/cycle_analytics/base_stage.rb @@ -29,7 +29,7 @@ module Gitlab # We compute the (end_time - start_time) interval, and give it an alias based on the current # cycle analytics stage. interval_query = Arel::Nodes::As.new(cte_table, - subtract_datetimes(base_query(project_ids), start_time_attrs, end_time_attrs, name.to_s)) + subtract_datetimes(stage_query(project_ids), start_time_attrs, end_time_attrs, name.to_s)) median_datetimes(cte_table, interval_query, name, :project_id)&.each do |project_id, median| loader.call(project_id, median) diff --git a/lib/gitlab/cycle_analytics/production_helper.rb b/lib/gitlab/cycle_analytics/production_helper.rb index ad1b2a007f6..d0ca62e46e4 100644 --- a/lib/gitlab/cycle_analytics/production_helper.rb +++ b/lib/gitlab/cycle_analytics/production_helper.rb @@ -1,7 +1,7 @@ module Gitlab module CycleAnalytics module ProductionHelper - def stage_query(project_ids = nil) + def stage_query(project_ids) super(project_ids) .where(mr_metrics_table[:first_deployed_to_production_at] .gteq(@options[:from])) # rubocop:disable Gitlab/ModuleWithInstanceVariables diff --git a/lib/gitlab/cycle_analytics/test_stage.rb b/lib/gitlab/cycle_analytics/test_stage.rb index f47f313d35d..0e9d235ca79 100644 --- a/lib/gitlab/cycle_analytics/test_stage.rb +++ b/lib/gitlab/cycle_analytics/test_stage.rb @@ -25,7 +25,7 @@ module Gitlab _("Total test time for all commits/merges") end - def stage_query(project_ids = nil) + def stage_query(project_ids) if @options[:branch] super(project_ids).where(build_table[:ref].eq(@options[:branch])) else |