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:
authorAndreas Brandl <abrandl@gitlab.com>2018-03-06 22:09:01 +0300
committerAndreas Brandl <abrandl@gitlab.com>2018-03-16 15:35:25 +0300
commit754272e392c0da088200a1b56156600973f63267 (patch)
tree21fdb2f633deff884d39d89f7672f230f1d6c143 /app/models/concerns/atomic_internal_id.rb
parenta0abb904782970de456dae5539ad5de2afef0e05 (diff)
Atomic generation of internal ids for issues.
Diffstat (limited to 'app/models/concerns/atomic_internal_id.rb')
-rw-r--r--app/models/concerns/atomic_internal_id.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/app/models/concerns/atomic_internal_id.rb b/app/models/concerns/atomic_internal_id.rb
new file mode 100644
index 00000000000..3cc9ce7f03f
--- /dev/null
+++ b/app/models/concerns/atomic_internal_id.rb
@@ -0,0 +1,19 @@
+module AtomicInternalId
+ extend ActiveSupport::Concern
+
+ included do
+ before_validation(on: :create) do
+ set_iid
+ end
+
+ validates :iid, presence: true, numericality: true
+ end
+
+ def set_iid
+ self.iid = InternalId.generate_next(self.project, :issues) if iid.blank?
+ end
+
+ def to_param
+ iid.to_s
+ end
+end