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
698ba370
Commit
698ba370
authored
Mar 24, 2021
by
Igor Drozdov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove N+1 for API commits/:sha/merge_requests
When a commit belongs to multiple MRs, N+1 is performed
parent
6f196179
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
4 deletions
+23
-4
changelogs/unreleased/id-n-1-for-merge-request-commits.yml
changelogs/unreleased/id-n-1-for-merge-request-commits.yml
+5
-0
lib/api/commits.rb
lib/api/commits.rb
+1
-1
spec/requests/api/commits_spec.rb
spec/requests/api/commits_spec.rb
+17
-3
No files found.
changelogs/unreleased/id-n-1-for-merge-request-commits.yml
0 → 100644
View file @
698ba370
---
title
:
Remove N+1 for API commits/:sha/merge_requests
merge_request
:
57290
author
:
type
:
performance
lib/api/commits.rb
View file @
698ba370
...
...
@@ -372,7 +372,7 @@ module API
current_user
,
project_id:
user_project
.
id
,
commit_sha:
commit
.
sha
).
execute
).
execute
.
with_api_entity_associations
present
paginate
(
commit_merge_requests
),
with:
Entities
::
MergeRequestBasic
end
...
...
spec/requests/api/commits_spec.rb
View file @
698ba370
...
...
@@ -1898,8 +1898,12 @@ RSpec.describe API::Commits do
let
(
:merged_mr
)
{
create
(
:merge_request
,
source_project:
project
,
source_branch:
'master'
,
target_branch:
'feature'
)
}
let
(
:commit
)
{
merged_mr
.
merge_request_diff
.
commits
.
last
}
it
'returns the correct merge request'
do
def
perform_request
(
user
)
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
commit
.
id
}
/merge_requests"
,
user
)
end
it
'returns the correct merge request'
do
perform_request
(
user
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
include_limited_pagination_headers
...
...
@@ -1910,7 +1914,7 @@ RSpec.describe API::Commits do
it
'returns 403 for an unauthorized user'
do
project
.
add_guest
(
user
)
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
commit
.
id
}
/merge_requests"
,
user
)
perform_request
(
user
)
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
end
...
...
@@ -1926,11 +1930,21 @@ RSpec.describe API::Commits do
let
(
:non_member
)
{
create
(
:user
)
}
it
'responds 403 when only members are allowed to read merge requests'
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
commit
.
id
}
/merge_requests"
,
non_member
)
perform_request
(
non_member
)
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
end
end
it
'returns multiple merge requests without N + 1'
do
perform_request
(
user
)
control_count
=
ActiveRecord
::
QueryRecorder
.
new
{
perform_request
(
user
)
}.
count
create
(
:merge_request
,
:closed
,
source_project:
project
,
source_branch:
'master'
,
target_branch:
'feature'
)
expect
{
perform_request
(
user
)
}.
not_to
exceed_query_limit
(
control_count
)
end
end
describe
'GET /projects/:id/repository/commits/:sha/signature'
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