diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/models/project_statistics.rb | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/app/models/project_statistics.rb b/app/models/project_statistics.rb index e13f8d28c92..f108e43015e 100644 --- a/app/models/project_statistics.rb +++ b/app/models/project_statistics.rb @@ -37,7 +37,6 @@ class ProjectStatistics < ApplicationRecord :pipeline_artifacts_size, :uploads_size ].freeze - STORAGE_SIZE_SUM = STORAGE_SIZE_COMPONENTS.map { |component| "COALESCE (#{component}, 0)" }.join(' + ').freeze scope :for_project_ids, ->(project_ids) { where(project_id: project_ids) } @@ -109,12 +108,12 @@ class ProjectStatistics < ApplicationRecord end def update_storage_size - self.storage_size = STORAGE_SIZE_COMPONENTS.sum { |component| method(component).call } + self.storage_size = storage_size_components.sum { |component| method(component).call } end def refresh_storage_size! detect_race_on_record(log_fields: { caller: __method__, attributes: :storage_size }) do - update!(storage_size: STORAGE_SIZE_SUM) + update!(storage_size: storage_size_sum) end end @@ -151,6 +150,14 @@ class ProjectStatistics < ApplicationRecord private + def storage_size_components + STORAGE_SIZE_COMPONENTS + end + + def storage_size_sum + storage_size_components.map { |component| "COALESCE (#{component}, 0)" }.join(' + ').freeze + end + def increment_columns!(key, amount) increments = { key => amount } additional = INCREMENTABLE_COLUMNS.fetch(key, []) |