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
a9e1626a
Commit
a9e1626a
authored
Mar 24, 2021
by
Igor Drozdov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove N+1 for API :id/deploy_keys
parent
6f196179
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
10 deletions
+28
-10
changelogs/unreleased/id-n-1-for-deploy-keys.yml
changelogs/unreleased/id-n-1-for-deploy-keys.yml
+5
-0
lib/api/deploy_keys.rb
lib/api/deploy_keys.rb
+1
-1
spec/requests/api/deploy_keys_spec.rb
spec/requests/api/deploy_keys_spec.rb
+22
-9
No files found.
changelogs/unreleased/id-n-1-for-deploy-keys.yml
0 → 100644
View file @
a9e1626a
---
title
:
Remove N+1 for API :id/deploy_keys
merge_request
:
57295
author
:
type
:
performance
lib/api/deploy_keys.rb
View file @
a9e1626a
...
...
@@ -44,7 +44,7 @@ module API
end
# rubocop: disable CodeReuse/ActiveRecord
get
":id/deploy_keys"
do
keys
=
user_project
.
deploy_keys_projects
.
preload
(
:deploy_key
)
keys
=
user_project
.
deploy_keys_projects
.
preload
(
deploy_key: :user
)
present
paginate
(
keys
),
with:
Entities
::
DeployKeysProject
end
...
...
spec/requests/api/deploy_keys_spec.rb
View file @
a9e1626a
...
...
@@ -3,12 +3,13 @@
require
'spec_helper'
RSpec
.
describe
API
::
DeployKeys
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:maintainer
)
{
create
(
:user
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:project
)
{
create
(
:project
,
creator_id:
user
.
id
)
}
let
(
:project2
)
{
create
(
:project
,
creator_id:
user
.
id
)
}
let
(
:deploy_key
)
{
create
(
:deploy_key
,
public:
true
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:maintainer
)
{
create
(
:user
)
}
let_it_be
(
:admin
)
{
create
(
:admin
)
}
let_it_be
(
:project
)
{
create
(
:project
,
creator_id:
user
.
id
)
}
let_it_be
(
:project2
)
{
create
(
:project
,
creator_id:
user
.
id
)
}
let
(
:deploy_key
)
{
create
(
:deploy_key
,
public:
true
)
}
let!
(
:deploy_keys_project
)
do
create
(
:deploy_keys_project
,
project:
project
,
deploy_key:
deploy_key
)
...
...
@@ -44,18 +45,30 @@ RSpec.describe API::DeployKeys do
end
describe
'GET /projects/:id/deploy_keys'
do
before
do
deploy_key
let
(
:deploy_key
)
{
create
(
:deploy_key
,
public:
true
,
user:
admin
)
}
def
perform_request
get
api
(
"/projects/
#{
project
.
id
}
/deploy_keys"
,
admin
)
end
it
'returns array of ssh keys'
do
get
api
(
"/projects/
#{
project
.
id
}
/deploy_keys"
,
admin
)
perform_request
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
deploy_key
.
title
)
end
it
'returns multiple deploy keys without N + 1'
do
perform_request
control_count
=
ActiveRecord
::
QueryRecorder
.
new
{
perform_request
}.
count
create
(
:deploy_key
,
public:
true
,
projects:
[
project
],
user:
maintainer
)
expect
{
perform_request
}.
not_to
exceed_query_limit
(
control_count
)
end
end
describe
'GET /projects/:id/deploy_keys/:key_id'
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