Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-12-20 12:08:36 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-12-20 12:08:36 +0300
commit19e00b948726c0f7ca27dd92200493803499a4e1 (patch)
tree0df898db4ba20af4b4de2baf39285fe4d113d148 /lib/gitlab/counters
parentca5ebd2044ce696cc1aafc8a80a606e20f2c9e4b (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/counters')
-rw-r--r--lib/gitlab/counters/buffered_counter.rb14
-rw-r--r--lib/gitlab/counters/legacy_counter.rb19
2 files changed, 32 insertions, 1 deletions
diff --git a/lib/gitlab/counters/buffered_counter.rb b/lib/gitlab/counters/buffered_counter.rb
index 56593b642a9..e662dfeef1e 100644
--- a/lib/gitlab/counters/buffered_counter.rb
+++ b/lib/gitlab/counters/buffered_counter.rb
@@ -41,6 +41,20 @@ module Gitlab
result
end
+ def bulk_increment(increments)
+ result = redis_state do |redis|
+ redis.pipelined do |pipeline|
+ increments.each do |increment|
+ pipeline.incrby(key, increment)
+ end
+ end
+ end
+
+ FlushCounterIncrementsWorker.perform_in(WORKER_DELAY, counter_record.class.name, counter_record.id, attribute)
+
+ result.last
+ end
+
def reset!
counter_record.update!(attribute => 0)
diff --git a/lib/gitlab/counters/legacy_counter.rb b/lib/gitlab/counters/legacy_counter.rb
index 06951514ec3..98cf8853321 100644
--- a/lib/gitlab/counters/legacy_counter.rb
+++ b/lib/gitlab/counters/legacy_counter.rb
@@ -12,7 +12,7 @@ module Gitlab
end
def increment(amount)
- updated = counter_record.class.update_counters(counter_record.id, { attribute => amount })
+ updated = update_counter_record_attribute(amount)
if updated == 1
counter_record.execute_after_commit_callbacks
@@ -22,12 +22,29 @@ module Gitlab
@current_value
end
+ def bulk_increment(increments)
+ total_increment = increments.sum
+
+ updated = update_counter_record_attribute(total_increment)
+
+ if updated == 1
+ counter_record.execute_after_commit_callbacks
+ @current_value += total_increment
+ end
+
+ @current_value
+ end
+
def reset!
counter_record.update!(attribute => 0)
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