diff options
Diffstat (limited to 'app/models/project_statistics.rb')
-rw-r--r-- | app/models/project_statistics.rb | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/app/models/project_statistics.rb b/app/models/project_statistics.rb index 506f6305791..732dadc03d9 100644 --- a/app/models/project_statistics.rb +++ b/app/models/project_statistics.rb @@ -123,16 +123,37 @@ class ProjectStatistics < ApplicationRecord # through counter_attribute_after_commit # # For non-counter attributes, storage_size is updated depending on key => [columns] in INCREMENTABLE_COLUMNS - def self.increment_statistic(project, key, amount) + def self.increment_statistic(project, key, increment) + return if project.pending_delete? + + project.statistics.try do |project_statistics| + project_statistics.increment_statistic(key, increment) + end + end + + def self.bulk_increment_statistic(project, key, increments) + unless Feature.enabled?(:project_statistics_bulk_increment, type: :development) + total_amount = Gitlab::Counters::Increment.new(amount: increments.sum(&:amount)) + return increment_statistic(project, key, total_amount) + end + + return if project.pending_delete? + project.statistics.try do |project_statistics| - project_statistics.increment_statistic(key, amount) + project_statistics.bulk_increment_statistic(key, increments) end end - def increment_statistic(key, amount) + def increment_statistic(key, increment) + raise ArgumentError, "Cannot increment attribute: #{key}" unless incrementable_attribute?(key) + + increment_counter(key, increment) + end + + def bulk_increment_statistic(key, increments) raise ArgumentError, "Cannot increment attribute: #{key}" unless incrementable_attribute?(key) - increment_counter(key, amount) + bulk_increment_counter(key, increments) end private |