Skip to content
Snippets Groups Projects
Commit 9488b778 authored by Alexis Reigel's avatar Alexis Reigel
Browse files

optimize query, only select relevant db columns

parent 4e53131f
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -7,6 +7,7 @@ module Gitlab
 
def run
GpgSignature
.select(:id, :commit_sha, :project_id)
.where('gpg_key_id IS NULL OR valid_signature = ?', false)
.where(gpg_key_primary_keyid: @gpg_key.primary_keyid)
.find_each do |gpg_signature|
Loading
Loading
Loading
Loading
@@ -20,7 +20,7 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
end
 
before do
allow_any_instance_of(GpgSignature).to receive(:commit).and_return(commit)
allow_any_instance_of(Project).to receive(:commit).and_return(commit)
end
 
context 'gpg signature did have an associated gpg key which was removed later' do
Loading
Loading
@@ -41,7 +41,13 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
key: GpgHelpers::User1.public_key,
user: user
 
expect(valid_gpg_signature.reload.gpg_key).to eq gpg_key
expect(valid_gpg_signature.reload).to have_attributes(
project: project,
commit_sha: commit_sha,
gpg_key: gpg_key,
gpg_key_primary_keyid: GpgHelpers::User1.primary_keyid,
valid_signature: true
)
end
 
it 'does not assign the gpg key when an unrelated gpg key is added' do
Loading
Loading
@@ -50,7 +56,13 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
key: GpgHelpers::User2.public_key,
user: user
 
expect(valid_gpg_signature.reload.gpg_key).to be_nil
expect(valid_gpg_signature.reload).to have_attributes(
project: project,
commit_sha: commit_sha,
gpg_key: nil,
gpg_key_primary_keyid: GpgHelpers::User1.primary_keyid,
valid_signature: true
)
end
end
 
Loading
Loading
@@ -68,11 +80,17 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
 
it 'updates the signature to being valid when the missing gpg key is added' do
# InvalidGpgSignatureUpdater is called by the after_create hook
create :gpg_key,
gpg_key = create :gpg_key,
key: GpgHelpers::User1.public_key,
user: user
 
expect(invalid_gpg_signature.reload.valid_signature).to be_truthy
expect(invalid_gpg_signature.reload).to have_attributes(
project: project,
commit_sha: commit_sha,
gpg_key: gpg_key,
gpg_key_primary_keyid: GpgHelpers::User1.primary_keyid,
valid_signature: true
)
end
 
it 'keeps the signature at being invalid when an unrelated gpg key is added' do
Loading
Loading
@@ -81,7 +99,13 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
key: GpgHelpers::User2.public_key,
user: user
 
expect(invalid_gpg_signature.reload.valid_signature).to be_falsey
expect(invalid_gpg_signature.reload).to have_attributes(
project: project,
commit_sha: commit_sha,
gpg_key: nil,
gpg_key_primary_keyid: GpgHelpers::User1.primary_keyid,
valid_signature: false
)
end
end
 
Loading
Loading
@@ -102,7 +126,7 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
end
 
it 'updates the signature to being valid when the user updates the email address' do
create :gpg_key,
gpg_key = create :gpg_key,
key: GpgHelpers::User1.public_key,
user: user
 
Loading
Loading
@@ -111,20 +135,38 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
# InvalidGpgSignatureUpdater is called by the after_update hook
user.update_attributes!(email: GpgHelpers::User1.emails.first)
 
expect(invalid_gpg_signature.reload.valid_signature).to be_truthy
expect(invalid_gpg_signature.reload).to have_attributes(
project: project,
commit_sha: commit_sha,
gpg_key: gpg_key,
gpg_key_primary_keyid: GpgHelpers::User1.primary_keyid,
valid_signature: true
)
end
 
it 'keeps the signature at being invalid when the changed email address is still unrelated' do
create :gpg_key,
gpg_key = create :gpg_key,
key: GpgHelpers::User1.public_key,
user: user
 
expect(invalid_gpg_signature.reload.valid_signature).to be_falsey
expect(invalid_gpg_signature.reload).to have_attributes(
project: project,
commit_sha: commit_sha,
gpg_key: gpg_key,
gpg_key_primary_keyid: GpgHelpers::User1.primary_keyid,
valid_signature: false
)
 
# InvalidGpgSignatureUpdater is called by the after_update hook
user.update_attributes!(email: 'still.unrelated@example.com')
 
expect(invalid_gpg_signature.reload.valid_signature).to be_falsey
expect(invalid_gpg_signature.reload).to have_attributes(
project: project,
commit_sha: commit_sha,
gpg_key: gpg_key,
gpg_key_primary_keyid: GpgHelpers::User1.primary_keyid,
valid_signature: false
)
end
end
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment