summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2017-09-07 23:14:07 +0900
committerShinya Maeda <shinya@gitlab.com>2017-09-07 23:14:07 +0900
commitc5377b97968ba9edefe7766dac77cc9fbbaa4e2c (patch)
treed7831a702d7cd7510075572f77d6a561ab2eed6a /app/models
parentf946558bb3b4ba6ff67a8c306af249b8d5350f39 (diff)
downloadgitlab-ce-c5377b97968ba9edefe7766dac77cc9fbbaa4e2c.tar.gz
Finished internal_id2. But this should be done by transaction
Diffstat (limited to 'app/models')
-rw-r--r--app/models/concerns/internal_id2.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/app/models/concerns/internal_id2.rb b/app/models/concerns/internal_id2.rb
index 08f128b4042..b64c831adc0 100644
--- a/app/models/concerns/internal_id2.rb
+++ b/app/models/concerns/internal_id2.rb
@@ -1,6 +1,8 @@
module InternalId2
extend ActiveSupport::Concern
+ FailedToSaveInternalIdError = Class.new(StandardError)
+
included do
after_commit :set_iid, on: :create
end
@@ -14,17 +16,17 @@ module InternalId2
retries ||= 0
max_iid = records.maximum(:iid) || -1
update_columns(iid: max_iid.to_i + 1) # Avoid infinite loop
- rescue ActiveRecord::RecordNotUnique => e
+ rescue ActiveRecord::RecordNotUnique
if (retries += 1) < 3
retry
else
- raise ActiveRecord::RecordInvalid
+ raise FailedToSaveInternalIdError
end
end
end
def table_name
self.class.name.deconstantize.split("::").map(&:underscore).join('_')
- + self.class.name.demodulize.tableize
+ + self.class.name.demodulize.tableize
end
end