diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-20 18:40:28 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-20 18:40:28 +0300 |
commit | b595cb0c1dec83de5bdee18284abe86614bed33b (patch) | |
tree | 8c3d4540f193c5ff98019352f554e921b3a41a72 /lib/gitlab/signed_commit.rb | |
parent | 2f9104a328fc8a4bddeaa4627b595166d24671d0 (diff) |
Add latest changes from gitlab-org/gitlab@15-2-stable-eev15.2.0-rc42
Diffstat (limited to 'lib/gitlab/signed_commit.rb')
-rw-r--r-- | lib/gitlab/signed_commit.rb | 35 |
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 |