diff options
author | Alexis Reigel <mail@koffeinfrei.org> | 2017-06-14 12:51:34 +0300 |
---|---|---|
committer | Alexis Reigel <mail@koffeinfrei.org> | 2017-07-27 16:42:53 +0300 |
commit | 69e511c4c2a0409fa69658cf95bf5c4072b2b2d0 (patch) | |
tree | 416321052fa4614973a5f29c8f76c05c97b6d84a /app | |
parent | 8236b12dff3df6d223888664c820ae54b4e0eaf7 (diff) |
cache the gpg commit signature
we store the result of the gpg commit verification in the db because the
gpg verification is an expensive operation.
Diffstat (limited to 'app')
-rw-r--r-- | app/models/commit.rb | 25 | ||||
-rw-r--r-- | app/views/projects/commit/_signature.html.haml | 6 |
2 files changed, 8 insertions, 23 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb index a6a11a2d3a5..6c5556902ec 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -239,29 +239,14 @@ class Commit @signature = nil - signature, signed_text = @raw.signature(project.repository) + cached_signature = GpgSignature.find_by(commit_sha: sha) + return cached_signature if cached_signature.present? - return unless signature && signed_text + gpg_commit = Gitlab::Gpg::Commit.new(self) - Gitlab::Gpg.using_tmp_keychain do - # first we need to get the keyid from the signature... - GPGME::Crypto.new.verify(signature, signed_text: signed_text) do |verified_signature| - @signature = verified_signature - end - - # ... then we query the gpg key belonging to the keyid. - gpg_key = GpgKey.find_by(primary_keyid: @signature.fingerprint) - - return @signature unless gpg_key - - Gitlab::Gpg::CurrentKeyChain.add(gpg_key.key) - - GPGME::Crypto.new.verify(signature, signed_text: signed_text) do |verified_signature| - @signature = verified_signature - end - end + return unless gpg_commit.has_signature? - @signature + @signature = gpg_commit.signature end def revert_branch_name diff --git a/app/views/projects/commit/_signature.html.haml b/app/views/projects/commit/_signature.html.haml index 7335b6b9597..48665ede6eb 100644 --- a/app/views/projects/commit/_signature.html.haml +++ b/app/views/projects/commit/_signature.html.haml @@ -1,4 +1,4 @@ - if signature - %a.btn.disabled.btn-xs{ class: ('btn-success' if signature.valid?) } - %i.fa.fa-key{ class: ('fa-inverse' if signature.valid?) } - = signature.valid? ? 'Verified': 'Unverified' + %a.btn.disabled.btn-xs{ class: ('btn-success' if signature.valid_signature?) } + %i.fa.fa-key{ class: ('fa-inverse' if signature.valid_signature?) } + = signature.valid_signature? ? 'Verified' : 'Unverified' |