diff --git a/app/models/cycle_analytics.rb b/app/models/cycle_analytics.rb index 8a57298f824..52eb07ae7d6 100644 --- a/app/models/cycle_analytics.rb +++ b/app/models/cycle_analytics.rb @@ -7,13 +7,8 @@ class CycleAnalytics end def all_medians_per_stage - medians_per_stage = {} - - # We only need this data for Postgres instances - return medians_per_stage if Gitlab::Database.mysql? - - STAGES.each do |stage_name| - medians_per_stage[stage_name] = self[stage_name].median + STAGES.each_with_object({}) do |stage_name, hsh| + hsh[stage_name] = self[stage_name].median end end diff --git a/lib/gitlab/cycle_analytics/base_query.rb b/lib/gitlab/cycle_analytics/base_query.rb index cd3d19db28e..b9075047487 100644 --- a/lib/gitlab/cycle_analytics/base_query.rb +++ b/lib/gitlab/cycle_analytics/base_query.rb @@ -8,14 +8,14 @@ module Gitlab private def base_query - @base_query ||= stage_query([@project.id]) + @base_query ||= stage_query([@project.id]) # rubocop:disable Gitlab/ModuleWithInstanceVariables end 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])) .project(issue_table[:project_id].as("project_id")) - .where(issue_table[:project_id].in(project_ids)) # rubocop:disable Gitlab/ModuleWithInstanceVariables + .where(issue_table[:project_id].in(project_ids)) .where(issue_table[:created_at].gteq(@options[:from])) # rubocop:disable Gitlab/ModuleWithInstanceVariables # Load merge_requests diff --git a/lib/gitlab/usage_data.rb b/lib/gitlab/usage_data.rb index 1fa000e933c..dae0e20e156 100644 --- a/lib/gitlab/usage_data.rb +++ b/lib/gitlab/usage_data.rb @@ -73,6 +73,9 @@ module Gitlab end def cycle_analytics_usage_data + # We only want to generate this data for instances that use PostgreSQL + return {} if Gitlab::Database.mysql? + projects = Project.sorted_by_activity.limit(Gitlab::CycleAnalytics::UsageData::PROJECTS_LIMIT) Gitlab::CycleAnalytics::UsageData.new(projects, { from: 7.days.ago }).to_json diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb index 0e9ecff25a6..138d21ede97 100644 --- a/spec/lib/gitlab/usage_data_spec.rb +++ b/spec/lib/gitlab/usage_data_spec.rb @@ -36,6 +36,7 @@ describe Gitlab::UsageData do gitlab_shared_runners git database + avg_cycle_analytics )) end diff --git a/spec/support/cycle_analytics_helpers/test_generation.rb b/spec/support/cycle_analytics_helpers/test_generation.rb index 19b32c84d81..da501a5077a 100644 --- a/spec/support/cycle_analytics_helpers/test_generation.rb +++ b/spec/support/cycle_analytics_helpers/test_generation.rb @@ -50,7 +50,7 @@ module CycleAnalyticsHelpers end median_time_difference = time_differences.sort[2] - expect(subject[phase].median).to be_within(5).of(median_time_difference) + expect(subject[phase].median.presence).to be_within(5).of(median_time_difference) end context "when the data belongs to another project" do