summaryrefslogtreecommitdiff
path: root/lib/gitlab/counters/legacy_counter.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/counters/legacy_counter.rb')
-rw-r--r--lib/gitlab/counters/legacy_counter.rb23
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/gitlab/counters/legacy_counter.rb b/lib/gitlab/counters/legacy_counter.rb
index 06951514ec3..823f9955168 100644
--- a/lib/gitlab/counters/legacy_counter.rb
+++ b/lib/gitlab/counters/legacy_counter.rb
@@ -11,23 +11,36 @@ module Gitlab
@current_value = counter_record.method(attribute).call
end
- def increment(amount)
- updated = counter_record.class.update_counters(counter_record.id, { attribute => amount })
+ def increment(increment)
+ updated = update_counter_record_attribute(increment.amount)
if updated == 1
counter_record.execute_after_commit_callbacks
- @current_value += amount
+ @current_value += increment.amount
end
@current_value
end
- def reset!
- counter_record.update!(attribute => 0)
+ def bulk_increment(increments)
+ total_increment = increments.sum(&:amount)
+
+ updated = update_counter_record_attribute(total_increment)
+
+ if updated == 1
+ counter_record.execute_after_commit_callbacks
+ @current_value += total_increment
+ end
+
+ @current_value
end
private
+ def update_counter_record_attribute(amount)
+ counter_record.class.update_counters(counter_record.id, { attribute => amount })
+ end
+
attr_reader :counter_record, :attribute
end
end