Commit c2a74490 authored by Stan Hu's avatar Stan Hu

Merge branch 'update-size-after-commit' into 'master'

Update size after commit

See merge request gitlab-org/gitlab!20852
parents ff7f6c1f b8991d4b
......@@ -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
......
---
title: UpdateProjectStatistics updates after commit
merge_request: 20852
author:
type: performance
......@@ -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
......
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