Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
17fc5fc5
Commit
17fc5fc5
authored
Jun 28, 2017
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent unnecessary `select`s and `remove_key`s
parent
e4e7e9c3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
5 deletions
+44
-5
lib/gitlab/shell.rb
lib/gitlab/shell.rb
+7
-5
spec/lib/gitlab/shell_spec.rb
spec/lib/gitlab/shell_spec.rb
+37
-0
No files found.
lib/gitlab/shell.rb
View file @
17fc5fc5
...
...
@@ -248,15 +248,17 @@ module Gitlab
return
unless
self
.
authorized_keys_enabled?
batch_read_key_ids
do
|
ids_in_file
|
ids_in_file
.
uniq!
keys_in_db
=
Key
.
where
(
id:
ids_in_file
)
if
ids_in_file
.
size
>
keys_in_db
.
count
return
unless
ids_in_file
.
size
>
keys_in_db
.
count
# optimization
ids_to_remove
=
ids_in_file
-
keys_in_db
.
pluck
(
:id
)
ids_to_remove
.
each
do
|
id
|
remove_key
(
"key-
#{
id
}
"
)
end
end
end
end
# Iterate over all ssh key IDs from gitlab shell, in batches
#
...
...
spec/lib/gitlab/shell_spec.rb
View file @
17fc5fc5
...
...
@@ -289,6 +289,43 @@ describe Gitlab::Shell, lib: true do
expect
(
find_in_authorized_keys_file
(
@another_key
.
id
)).
to
be_truthy
end
end
context
'when keys there are duplicate keys in the file that are not in the DB'
do
before
do
gitlab_shell
.
remove_all_keys
gitlab_shell
.
add_key
(
'key-1234'
,
'ssh-rsa ASDFASDF'
)
gitlab_shell
.
add_key
(
'key-1234'
,
'ssh-rsa ASDFASDF'
)
end
it
'removes the keys'
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
it
'does not run remove more than once per key (in a batch)'
do
expect
(
gitlab_shell
).
to
receive
(
:remove_key
).
with
(
'key-1234'
).
once
gitlab_shell
.
remove_keys_not_found_in_db
end
end
context
'when keys there are duplicate keys in the file that ARE in the DB'
do
before
do
gitlab_shell
.
remove_all_keys
@key
=
create
(
:key
)
gitlab_shell
.
add_key
(
@key
.
shell_id
,
@key
.
key
)
end
it
'does not remove the key'
do
gitlab_shell
.
remove_keys_not_found_in_db
expect
(
find_in_authorized_keys_file
(
@key
.
id
)).
to
be_truthy
end
it
'does not need to run a SELECT query for that batch, on account of that key'
do
expect_any_instance_of
(
ActiveRecord
::
Relation
).
not_to
receive
(
:pluck
)
gitlab_shell
.
remove_keys_not_found_in_db
end
end
end
describe
'#batch_read_key_ids'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment