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
ab9d6cd1
Commit
ab9d6cd1
authored
May 12, 2020
by
James Fargher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix N+1 in storage move API
Also improves permissions coverage
parent
07885680
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
2 deletions
+34
-2
app/models/project_repository_storage_move.rb
app/models/project_repository_storage_move.rb
+1
-0
lib/api/project_repository_storage_moves.rb
lib/api/project_repository_storage_moves.rb
+1
-1
spec/requests/api/project_repository_storage_moves_spec.rb
spec/requests/api/project_repository_storage_moves_spec.rb
+32
-1
No files found.
app/models/project_repository_storage_move.rb
View file @
ab9d6cd1
...
...
@@ -54,4 +54,5 @@ class ProjectRepositoryStorageMove < ApplicationRecord
end
scope
:order_created_at_desc
,
->
{
order
(
created_at: :desc
)
}
scope
:with_projects
,
->
{
includes
(
project: :route
)
}
end
lib/api/project_repository_storage_moves.rb
View file @
ab9d6cd1
...
...
@@ -15,7 +15,7 @@ module API
use
:pagination
end
get
do
storage_moves
=
ProjectRepositoryStorageMove
.
order_created_at_desc
storage_moves
=
ProjectRepositoryStorageMove
.
with_projects
.
order_created_at_desc
present
paginate
(
storage_moves
),
with:
Entities
::
ProjectRepositoryStorageMove
,
current_user:
current_user
end
...
...
spec/requests/api/project_repository_storage_moves_spec.rb
View file @
ab9d6cd1
...
...
@@ -3,6 +3,8 @@
require
'spec_helper'
describe
API
::
ProjectRepositoryStorageMoves
do
include
AccessMatchersForRequest
let
(
:user
)
{
create
(
:admin
)
}
let!
(
:storage_move
)
{
create
(
:project_repository_storage_move
,
:scheduled
)
}
...
...
@@ -23,6 +25,9 @@ describe API::ProjectRepositoryStorageMoves do
end
it
'avoids N+1 queries'
,
:request_store
do
# prevent `let` from polluting the control
get_project_repository_storage_moves
control
=
ActiveRecord
::
QueryRecorder
.
new
{
get_project_repository_storage_moves
}
create
(
:project_repository_storage_move
,
:scheduled
)
...
...
@@ -43,16 +48,42 @@ describe API::ProjectRepositoryStorageMoves do
storage_move_oldest
.
id
])
end
describe
'permissions'
do
it
{
expect
{
get_project_repository_storage_moves
}.
to
be_allowed_for
(
:admin
)
}
it
{
expect
{
get_project_repository_storage_moves
}.
to
be_denied_for
(
:user
)
}
end
end
describe
'GET /project_repository_storage_moves/:id'
do
let
(
:project_repository_storage_move_id
)
{
storage_move
.
id
}
def
get_project_repository_storage_move
get
api
(
"/project_repository_storage_moves/
#{
project_repository_storage_move_id
}
"
,
user
)
end
it
'returns a project repository storage move'
do
get
api
(
"/project_repository_storage_moves/
#{
storage_move
.
id
}
"
,
user
)
get
_project_repository_storage_move
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
match_response_schema
(
'public_api/v4/project_repository_storage_move'
)
expect
(
json_response
[
'id'
]).
to
eq
(
storage_move
.
id
)
expect
(
json_response
[
'state'
]).
to
eq
(
storage_move
.
human_state_name
)
end
context
'non-existent project repository storage move'
do
let
(
:project_repository_storage_move_id
)
{
non_existing_record_id
}
it
'returns not found'
do
get_project_repository_storage_move
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
describe
'permissions'
do
it
{
expect
{
get_project_repository_storage_move
}.
to
be_allowed_for
(
:admin
)
}
it
{
expect
{
get_project_repository_storage_move
}.
to
be_denied_for
(
:user
)
}
end
end
end
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