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:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-07-12 00:08:18 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-07-12 00:08:18 +0300
commite3a138e3b91d976bee17696df3fdb2708e9f2367 (patch)
tree41c604d08cdcb03e5ab0e2a36b9f05d3bf341a03 /lib/gitlab/signed_commit.rb
parent57b0826587612684a950dff52ab291c299653a62 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/signed_commit.rb')
-rw-r--r--lib/gitlab/signed_commit.rb35
1 files changed, 34 insertions, 1 deletions
diff --git a/lib/gitlab/signed_commit.rb b/lib/gitlab/signed_commit.rb
index 7a154978938..410e71f51a1 100644
--- a/lib/gitlab/signed_commit.rb
+++ b/lib/gitlab/signed_commit.rb
@@ -18,7 +18,18 @@ module Gitlab
end
def signature
- return unless @commit.has_signature?
+ return @signature if @signature
+
+ cached_signature = lazy_signature&.itself
+
+ return @signature = cached_signature if cached_signature.present?
+
+ @signature = create_cached_signature!
+ end
+
+ def update_signature!(cached_signature)
+ cached_signature.update!(attributes)
+ @signature = cached_signature
end
def signature_text
@@ -32,5 +43,27 @@ module Gitlab
@signature_data.itself ? @signature_data[1] : nil
end
end
+
+ private
+
+ def signature_class
+ raise NotImplementedError, '`signature_class` must be implmented by subclass`'
+ end
+
+ def lazy_signature
+ BatchLoader.for(@commit.sha).batch do |shas, loader|
+ signature_class.by_commit_sha(shas).each do |signature|
+ loader.call(signature.commit_sha, signature)
+ end
+ end
+ end
+
+ def create_cached_signature!
+ return if attributes.nil?
+
+ return signature_class.new(attributes) if Gitlab::Database.read_only?
+
+ signature_class.safe_create!(attributes)
+ end
end
end