From 45a05a8ba33101ffcd154ee84307885b48b17962 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 28 Nov 2019 06:06:25 +0000 Subject: [PATCH] Add latest changes from gitlab-org/gitlab@master --- Gemfile | 4 +-- Gemfile.lock | 11 ++++---- .../concerns/update_project_statistics.rb | 28 +++++++++++++------ .../unreleased/update-size-after-commit.yml | 5 ++++ spec/models/ci/job_artifact_spec.rb | 20 +++++++++++-- 5 files changed, 50 insertions(+), 18 deletions(-) create mode 100644 changelogs/unreleased/update-size-after-commit.yml diff --git a/Gemfile b/Gemfile index 8ed9603856e..683950c048a 100644 --- a/Gemfile +++ b/Gemfile @@ -170,8 +170,8 @@ group :unicorn do end group :puma do - gem 'puma', '~> 3.12', require: false - gem 'puma_worker_killer', require: false + gem 'puma', '~> 4.3.0', require: false + gem 'puma_worker_killer', '~> 0.1.1', require: false gem 'rack-timeout', require: false end diff --git a/Gemfile.lock b/Gemfile.lock index ba40ebc6cb5..0f9b78cd8e9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -749,10 +749,11 @@ GEM pry-rails (0.3.6) pry (>= 0.10.4) public_suffix (3.1.1) - puma (3.12.0) - puma_worker_killer (0.1.0) + puma (4.3.0) + nio4r (~> 2.0) + puma_worker_killer (0.1.1) get_process_mem (~> 0.2) - puma (>= 2.7, < 4) + puma (>= 2.7, < 5) pyu-ruby-sasl (0.0.3.3) raabro (1.1.6) rack (2.0.7) @@ -1280,8 +1281,8 @@ DEPENDENCIES prometheus-client-mmap (~> 0.9.10) pry-byebug (~> 3.5.1) pry-rails (~> 0.3.4) - puma (~> 3.12) - puma_worker_killer + puma (~> 4.3.0) + puma_worker_killer (~> 0.1.1) rack (~> 2.0.7) rack-attack (~> 6.2.0) rack-cors (~> 1.0.0) diff --git a/app/models/concerns/update_project_statistics.rb b/app/models/concerns/update_project_statistics.rb index 869b3490f3f..a84fb1cf56d 100644 --- a/app/models/concerns/update_project_statistics.rb +++ b/app/models/concerns/update_project_statistics.rb @@ -49,8 +49,7 @@ module UpdateProjectStatistics attr = self.class.statistic_attribute delta = read_attribute(attr).to_i - attribute_before_last_save(attr).to_i - update_project_statistics(delta) - schedule_namespace_aggregation_worker + schedule_update_project_statistic(delta) end def update_project_statistics_attribute_changed? @@ -58,24 +57,35 @@ module UpdateProjectStatistics end def update_project_statistics_after_destroy - update_project_statistics(-read_attribute(self.class.statistic_attribute).to_i) + delta = -read_attribute(self.class.statistic_attribute).to_i - schedule_namespace_aggregation_worker + schedule_update_project_statistic(delta) end def project_destroyed? project.pending_delete? end - def update_project_statistics(delta) - ProjectStatistics.increment_statistic(project_id, self.class.project_statistics_name, delta) - end + def schedule_update_project_statistic(delta) + return if delta.zero? + + if Feature.enabled?(:update_project_statistics_after_commit, default_enabled: true) + # Update ProjectStatistics after the transaction + run_after_commit do + ProjectStatistics.increment_statistic( + project_id, self.class.project_statistics_name, delta) + end + else + # Use legacy-way to update within transaction + ProjectStatistics.increment_statistic( + project_id, self.class.project_statistics_name, delta) + end - def schedule_namespace_aggregation_worker run_after_commit do next if project.nil? - Namespaces::ScheduleAggregationWorker.perform_async(project.namespace_id) + Namespaces::ScheduleAggregationWorker.perform_async( + project.namespace_id) end end end diff --git a/changelogs/unreleased/update-size-after-commit.yml b/changelogs/unreleased/update-size-after-commit.yml new file mode 100644 index 00000000000..4e5f5cd6782 --- /dev/null +++ b/changelogs/unreleased/update-size-after-commit.yml @@ -0,0 +1,5 @@ +--- +title: UpdateProjectStatistics updates after commit +merge_request: 20852 +author: +type: performance diff --git a/spec/models/ci/job_artifact_spec.rb b/spec/models/ci/job_artifact_spec.rb index 1413da231e0..76e31fddd98 100644 --- a/spec/models/ci/job_artifact_spec.rb +++ b/spec/models/ci/job_artifact_spec.rb @@ -19,8 +19,24 @@ describe Ci::JobArtifact do it_behaves_like 'having unique enum values' - it_behaves_like 'UpdateProjectStatistics' do - subject { build(:ci_job_artifact, :archive, size: 106365) } + context 'with update_project_statistics_after_commit enabled' do + before do + stub_feature_flags(update_project_statistics_after_commit: true) + end + + it_behaves_like 'UpdateProjectStatistics' do + subject { build(:ci_job_artifact, :archive, size: 106365) } + end + end + + context 'with update_project_statistics_after_commit disabled' do + before do + stub_feature_flags(update_project_statistics_after_commit: false) + end + + it_behaves_like 'UpdateProjectStatistics' do + subject { build(:ci_job_artifact, :archive, size: 106365) } + end end describe '.with_reports' do