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:
authorBob Van Landuyt <bob@vanlanduyt.co>2019-02-05 20:22:25 +0300
committerBob Van Landuyt <bob@vanlanduyt.co>2019-02-06 17:24:46 +0300
commitc982edfa1969770696c2e85a8e32160eb0304cbc (patch)
treede446e480e2a89271b7871550d9904935c00e9ae /app/models/gpg_signature.rb
parent02cc32c65579573e340603d09280e5b9e88f7a01 (diff)
Avoid race conditions when creating GpgSignature
This avoids race conditions when creating GpgSignature.
Diffstat (limited to 'app/models/gpg_signature.rb')
-rw-r--r--app/models/gpg_signature.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/app/models/gpg_signature.rb b/app/models/gpg_signature.rb
index 0816778deae..7f9ff7bbda6 100644
--- a/app/models/gpg_signature.rb
+++ b/app/models/gpg_signature.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-class GpgSignature < ActiveRecord::Base
+class GpgSignature < ApplicationRecord
include ShaAttribute
sha_attribute :commit_sha
@@ -33,6 +33,11 @@ class GpgSignature < ActiveRecord::Base
)
end
+ def self.safe_create!(attributes)
+ create_with(attributes)
+ .safe_find_or_create_by!(commit_sha: attributes[:commit_sha])
+ end
+
def gpg_key=(model)
case model
when GpgKey