diff options
author | Alessio Caiazza <acaiazza@gitlab.com> | 2019-04-19 12:37:14 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2019-04-19 12:37:14 +0300 |
commit | fa2968256caf2a3e9eebfe0ceca0c71a60f06b06 (patch) | |
tree | c33d58ded9151624e8ceddb46a8a2cdb5350eb4c /app/models/ci/build.rb | |
parent | 1aa0ceae41c444fd18e37237497ecb8306a21307 (diff) |
Extract ProjectStatistics updates into a concern
Refactor existing tests as a shared example
Diffstat (limited to 'app/models/ci/build.rb')
-rw-r--r-- | app/models/ci/build.rb | 20 |
1 files changed, 2 insertions, 18 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 5cf9bb4979a..e5236051118 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -15,6 +15,7 @@ module Ci include Gitlab::Utils::StrongMemoize include Deployable include HasRef + include UpdateProjectStatistics BuildArchivedError = Class.new(StandardError) @@ -157,8 +158,7 @@ module Ci run_after_commit { BuildHooksWorker.perform_async(build.id) } end - after_save :update_project_statistics_after_save, if: :artifacts_size_changed? - after_destroy :update_project_statistics_after_destroy, unless: :project_destroyed? + update_project_statistics stat: :build_artifacts_size, attribute: :artifacts_size class << self # This is needed for url_for to work, @@ -847,21 +847,5 @@ module Ci pipeline.config_processor.build_attributes(name) end - - def update_project_statistics_after_save - update_project_statistics(read_attribute(:artifacts_size).to_i - artifacts_size_was.to_i) - end - - def update_project_statistics_after_destroy - update_project_statistics(-artifacts_size) - end - - def update_project_statistics(difference) - ProjectStatistics.increment_statistic(project_id, :build_artifacts_size, difference) - end - - def project_destroyed? - project.pending_delete? - end end end |