diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /app/models/concerns/counter_attribute.rb | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'app/models/concerns/counter_attribute.rb')
-rw-r--r-- | app/models/concerns/counter_attribute.rb | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/app/models/concerns/counter_attribute.rb b/app/models/concerns/counter_attribute.rb index 65cf3246d11..64d178b7507 100644 --- a/app/models/concerns/counter_attribute.rb +++ b/app/models/concerns/counter_attribute.rb @@ -65,6 +65,10 @@ module CounterAttribute def counter_attribute_after_flush(&callback) after_flush_callbacks << callback end + + def counter_attribute_enabled?(attribute) + counter_attributes.include?(attribute) + end end # This method must only be called by FlushCounterIncrementsWorker @@ -103,16 +107,14 @@ module CounterAttribute end def delayed_increment_counter(attribute, increment) + raise ArgumentError, "#{attribute} is not a counter attribute" unless counter_attribute_enabled?(attribute) + return if increment == 0 run_after_commit_or_now do - if counter_attribute_enabled?(attribute) - increment_counter(attribute, increment) + increment_counter(attribute, increment) - FlushCounterIncrementsWorker.perform_in(WORKER_DELAY, self.class.name, self.id, attribute) - else - legacy_increment!(attribute, increment) - end + FlushCounterIncrementsWorker.perform_in(WORKER_DELAY, self.class.name, self.id, attribute) end true @@ -157,7 +159,7 @@ module CounterAttribute end def counter_attribute_enabled?(attribute) - self.class.counter_attributes.include?(attribute) + self.class.counter_attribute_enabled?(attribute) end private @@ -168,10 +170,6 @@ module CounterAttribute end end - def legacy_increment!(attribute, increment) - increment!(attribute, increment) - end - def unsafe_update_counters(id, increments) self.class.update_counters(id, increments) end |