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
44777e66
Commit
44777e66
authored
Feb 19, 2021
by
Luke Duncalfe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix N+1 issues in API v3/repos/{full-path}/events
https://gitlab.com/gitlab-org/gitlab/-/issues/321839
parent
ecdb95a8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
0 deletions
+44
-0
config/feature_flags/development/api_v3_repos_events_optimization.yml
...re_flags/development/api_v3_repos_events_optimization.yml
+8
-0
lib/api/v3/github.rb
lib/api/v3/github.rb
+6
-0
spec/requests/api/v3/github_spec.rb
spec/requests/api/v3/github_spec.rb
+30
-0
No files found.
config/feature_flags/development/api_v3_repos_events_optimization.yml
0 → 100644
View file @
44777e66
---
name
:
api_v3_repos_events_optimization
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/54618
rollout_issue_url
:
https://gitlab.com/gitlab-org/gitlab/-/issues/322059
milestone
:
'
13.10'
type
:
development
group
:
group::ecosystem
default_enabled
:
false
lib/api/v3/github.rb
View file @
44777e66
...
@@ -194,13 +194,19 @@ module API
...
@@ -194,13 +194,19 @@ module API
# Self-hosted Jira (tested on 7.11.1) requests this endpoint right
# Self-hosted Jira (tested on 7.11.1) requests this endpoint right
# after fetching branches.
# after fetching branches.
# rubocop: disable CodeReuse/ActiveRecord
get
':namespace/:project/events'
do
get
':namespace/:project/events'
do
user_project
=
find_project_with_access
(
params
)
user_project
=
find_project_with_access
(
params
)
merge_requests
=
authorized_merge_requests_for_project
(
user_project
)
merge_requests
=
authorized_merge_requests_for_project
(
user_project
)
if
Feature
.
enabled?
(
:api_v3_repos_events_optimization
,
user_project
)
merge_requests
=
merge_requests
.
preload
(
:author
,
:assignees
,
:metrics
,
source_project: :namespace
,
target_project: :namespace
)
end
present
paginate
(
merge_requests
),
with:
::
API
::
Github
::
Entities
::
PullRequestEvent
present
paginate
(
merge_requests
),
with:
::
API
::
Github
::
Entities
::
PullRequestEvent
end
end
# rubocop: enable CodeReuse/ActiveRecord
params
do
params
do
use
:project_full_path
use
:project_full_path
...
...
spec/requests/api/v3/github_spec.rb
View file @
44777e66
...
@@ -149,6 +149,8 @@ RSpec.describe API::V3::Github do
...
@@ -149,6 +149,8 @@ RSpec.describe API::V3::Github do
end
end
describe
'GET events'
do
describe
'GET events'
do
include
ProjectForksHelper
let
(
:group
)
{
create
(
:group
)
}
let
(
:group
)
{
create
(
:group
)
}
let
(
:project
)
{
create
(
:project
,
:empty_repo
,
path:
'project.with.dot'
,
group:
group
)
}
let
(
:project
)
{
create
(
:project
,
:empty_repo
,
path:
'project.with.dot'
,
group:
group
)
}
let
(
:events_path
)
{
"/repos/
#{
group
.
path
}
/
#{
project
.
path
}
/events"
}
let
(
:events_path
)
{
"/repos/
#{
group
.
path
}
/
#{
project
.
path
}
/events"
}
...
@@ -174,6 +176,34 @@ RSpec.describe API::V3::Github do
...
@@ -174,6 +176,34 @@ RSpec.describe API::V3::Github do
end
end
end
end
it
'avoids N+1 queries'
do
create
(
:merge_request
,
source_project:
project
)
source_project
=
fork_project
(
project
,
nil
,
repository:
true
)
control_count
=
ActiveRecord
::
QueryRecorder
.
new
(
skip_cached:
false
)
{
jira_get
v3_api
(
events_path
,
user
)
}.
count
create_list
(
:merge_request
,
2
,
:unique_branches
,
source_project:
source_project
,
target_project:
project
)
expect
{
jira_get
v3_api
(
events_path
,
user
)
}.
not_to
exceed_all_query_limit
(
control_count
)
end
context
'with `api_v3_repos_events_optimization` feature flag disabled'
do
before
do
stub_feature_flags
(
api_v3_repos_events_optimization:
false
)
end
it
'falls back to less optimal query performance'
do
create
(
:merge_request
,
source_project:
project
)
source_project
=
fork_project
(
project
,
nil
,
repository:
true
)
control_count
=
ActiveRecord
::
QueryRecorder
.
new
(
skip_cached:
false
)
{
jira_get
v3_api
(
events_path
,
user
)
}.
count
create_list
(
:merge_request
,
2
,
:unique_branches
,
source_project:
source_project
,
target_project:
project
)
expect
{
jira_get
v3_api
(
events_path
,
user
)
}.
to
exceed_all_query_limit
(
control_count
)
end
end
context
'if there are more merge requests'
do
context
'if there are more merge requests'
do
let!
(
:merge_request
)
{
create
(
:merge_request
,
id:
10000
,
source_project:
project
,
target_project:
project
,
author:
user
)
}
let!
(
:merge_request
)
{
create
(
:merge_request
,
id:
10000
,
source_project:
project
,
target_project:
project
,
author:
user
)
}
let!
(
:merge_request2
)
{
create
(
:merge_request
,
id:
10001
,
source_project:
project
,
source_branch:
generate
(
:branch
),
target_project:
project
,
author:
user
)
}
let!
(
:merge_request2
)
{
create
(
:merge_request
,
id:
10001
,
source_project:
project
,
source_branch:
generate
(
:branch
),
target_project:
project
,
author:
user
)
}
...
...
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