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:
Diffstat (limited to 'app/models/concerns/counter_attribute.rb')
-rw-r--r--app/models/concerns/counter_attribute.rb20
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