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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
943fc87d
Commit
943fc87d
authored
Apr 24, 2018
by
Sean McGivern
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix an N+1 for MRs from forks on the MR index page
parent
26147b73
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
19 deletions
+40
-19
app/controllers/concerns/issuable_collections.rb
app/controllers/concerns/issuable_collections.rb
+2
-2
changelogs/unreleased/43111-controller-projects-mergerequestscontroller-index-executes-more-than-100-sql-queries.yml
...tscontroller-index-executes-more-than-100-sql-queries.yml
+5
-0
spec/support/shared_examples/issuables_list_metadata_shared_examples.rb
...hared_examples/issuables_list_metadata_shared_examples.rb
+33
-17
No files found.
app/controllers/concerns/issuable_collections.rb
View file @
943fc87d
...
...
@@ -165,8 +165,8 @@ module IssuableCollections
[
:project
,
:author
,
:assignees
,
:labels
,
:milestone
,
project: :namespace
]
when
'MergeRequest'
[
:
source_project
,
:
target_project
,
:author
,
:assignee
,
:labels
,
:milestone
,
head_pipeline: :project
,
target_project: :namespace
,
latest_merge_request_diff: :merge_request_diff_commits
:target_project
,
:author
,
:assignee
,
:labels
,
:milestone
,
source_project: :route
,
head_pipeline: :project
,
target_project: :namespace
,
latest_merge_request_diff: :merge_request_diff_commits
]
end
end
...
...
changelogs/unreleased/43111-controller-projects-mergerequestscontroller-index-executes-more-than-100-sql-queries.yml
0 → 100644
View file @
943fc87d
---
title
:
Reduce queries on merge requests list page for merge requests from forks
merge_request
:
18561
author
:
type
:
performance
spec/support/shared_examples/issuables_list_metadata_shared_examples.rb
View file @
943fc87d
shared_examples
'issuables list meta-data'
do
|
issuable_type
,
action
=
nil
|
before
do
@issuable_ids
=
[]
include
ProjectForksHelper
def
get_action
(
action
,
project
)
if
action
get
action
,
author_id:
project
.
creator
.
id
else
get
:index
,
namespace_id:
project
.
namespace
,
project_id:
project
end
end
%w[fix improve/awesome]
.
each
do
|
source_branch
|
issuable
=
def
create_issuable
(
issuable_type
,
project
,
source_branch
:)
if
issuable_type
==
:issue
create
(
issuable_type
,
project:
project
,
author:
project
.
creator
)
else
create
(
issuable_type
,
source_project:
project
,
source_branch:
source_branch
,
author:
project
.
creator
)
end
end
@issuable_ids
<<
issuable
.
id
before
do
@issuable_ids
=
%w[fix improve/awesome]
.
map
do
|
source_branch
|
create_issuable
(
issuable_type
,
project
,
source_branch:
source_branch
).
id
end
end
it
"creates indexed meta-data object for issuable notes and votes count"
do
if
action
get
action
,
author_id:
project
.
creator
.
id
else
get
:index
,
namespace_id:
project
.
namespace
,
project_id:
project
end
get_action
(
action
,
project
)
meta_data
=
assigns
(
:issuable_meta_data
)
...
...
@@ -29,18 +34,29 @@ shared_examples 'issuables list meta-data' do |issuable_type, action = nil|
end
end
it
"avoids N+1 queries"
do
control
=
ActiveRecord
::
QueryRecorder
.
new
{
get_action
(
action
,
project
)
}
issuable
=
create_issuable
(
issuable_type
,
project
,
source_branch:
'csv'
)
if
issuable_type
==
:merge_request
issuable
.
update!
(
source_project:
fork_project
(
project
))
end
expect
{
get_action
(
action
,
project
)
}.
not_to
exceed_query_limit
(
control
.
count
)
end
describe
"when given empty collection"
do
let
(
:project2
)
{
create
(
:project
,
:public
)
}
it
"doesn't execute any queries with false conditions"
do
get_
action
=
get_
empty
=
if
action
proc
{
get
action
,
author_id:
project
.
creator
.
id
}
else
proc
{
get
:index
,
namespace_id:
project2
.
namespace
,
project_id:
project2
}
end
expect
(
&
get_
action
).
not_to
make_queries_matching
(
/WHERE (?:1=0|0=1)/
)
expect
(
&
get_
empty
).
not_to
make_queries_matching
(
/WHERE (?:1=0|0=1)/
)
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