Commit 9756deec authored by Michael Kozono's avatar Michael Kozono

Fix optimization

parent 4949edce
...@@ -253,7 +253,7 @@ module Gitlab ...@@ -253,7 +253,7 @@ module Gitlab
ids_in_file.uniq! ids_in_file.uniq!
keys_in_db = Key.where(id: ids_in_file) keys_in_db = Key.where(id: ids_in_file)
return unless ids_in_file.size > keys_in_db.count # optimization next unless ids_in_file.size > keys_in_db.count # optimization
ids_to_remove = ids_in_file - keys_in_db.pluck(:id) ids_to_remove = ids_in_file - keys_in_db.pluck(:id)
ids_to_remove.each do |id| ids_to_remove.each do |id|
......
...@@ -326,6 +326,22 @@ describe Gitlab::Shell, lib: true do ...@@ -326,6 +326,22 @@ describe Gitlab::Shell, lib: true do
gitlab_shell.remove_keys_not_found_in_db gitlab_shell.remove_keys_not_found_in_db
end end
end end
unless ENV['CI'] # Skip in CI, it takes 1 minute
context 'when the first batch can be skipped, but the next batch has keys that are not in the DB' do
before do
gitlab_shell.remove_all_keys
100.times { |i| create(:key) } # first batch is all in the DB
gitlab_shell.add_key('key-1234', 'ssh-rsa ASDFASDF')
end
it 'removes the keys not in the DB' do
expect(find_in_authorized_keys_file(1234)).to be_truthy
gitlab_shell.remove_keys_not_found_in_db
expect(find_in_authorized_keys_file(1234)).to be_falsey
end
end
end
end end
describe '#batch_read_key_ids' do describe '#batch_read_key_ids' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment