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
19515cd4
Commit
19515cd4
authored
Sep 03, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
8e6a20bd
8326e84e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
3 deletions
+19
-3
app/controllers/admin/groups_controller.rb
app/controllers/admin/groups_controller.rb
+5
-1
app/models/concerns/routable.rb
app/models/concerns/routable.rb
+2
-2
changelogs/unreleased/ab-routable-nplus1.yml
changelogs/unreleased/ab-routable-nplus1.yml
+5
-0
spec/models/concerns/routable_spec.rb
spec/models/concerns/routable_spec.rb
+7
-0
No files found.
app/controllers/admin/groups_controller.rb
View file @
19515cd4
...
...
@@ -14,7 +14,11 @@ class Admin::GroupsController < Admin::ApplicationController
# rubocop: disable CodeReuse/ActiveRecord
def
show
@group
=
Group
.
with_statistics
.
joins
(
:route
).
group
(
'routes.path'
).
find_by_full_path
(
params
[
:id
])
# Group.with_statistics doesn't behave nicely when including other relations.
# Group.find_by_full_path includes the routes relation to avoid a common N+1
# (at the expense of this action: there are two queries here to find and retrieve
# the Group with statistics).
@group
=
Group
.
with_statistics
.
find
(
group
&
.
id
)
@members
=
present_members
(
@group
.
members
.
order
(
"access_level DESC"
).
page
(
params
[
:members_page
]))
@requesters
=
present_members
(
...
...
app/models/concerns/routable.rb
View file @
19515cd4
...
...
@@ -38,7 +38,7 @@ module Routable
if
Feature
.
enabled?
(
:routable_two_step_lookup
)
# Case sensitive match first (it's cheaper and the usual case)
# If we didn't have an exact match, we perform a case insensitive search
found
=
join
s
(
:route
).
find_by
(
routes:
{
path:
path
})
||
where_full_path_in
([
path
]).
take
found
=
include
s
(
:route
).
find_by
(
routes:
{
path:
path
})
||
where_full_path_in
([
path
]).
take
else
order_sql
=
Arel
.
sql
(
"(CASE WHEN routes.path =
#{
connection
.
quote
(
path
)
}
THEN 0 ELSE 1 END)"
)
found
=
where_full_path_in
([
path
]).
reorder
(
order_sql
).
take
...
...
@@ -67,7 +67,7 @@ module Routable
"(LOWER(routes.path) = LOWER(
#{
connection
.
quote
(
path
)
}
))"
end
joins
(
:route
).
where
(
wheres
.
join
(
' OR '
)
)
includes
(
:route
).
where
(
wheres
.
join
(
' OR '
)).
references
(
:routes
)
end
# Temporary instrumentation of method calls
...
...
changelogs/unreleased/ab-routable-nplus1.yml
0 → 100644
View file @
19515cd4
---
title
:
Preload routes information to fix N+1 issue
merge_request
:
32352
author
:
type
:
performance
spec/models/concerns/routable_spec.rb
View file @
19515cd4
...
...
@@ -66,6 +66,13 @@ describe Group, 'Routable' do
it
{
expect
(
described_class
.
find_by_full_path
(
group
.
to_param
.
upcase
)).
to
eq
(
group
)
}
it
{
expect
(
described_class
.
find_by_full_path
(
nested_group
.
to_param
)).
to
eq
(
nested_group
)
}
it
{
expect
(
described_class
.
find_by_full_path
(
'unknown'
)).
to
eq
(
nil
)
}
it
'includes route information when loading a record'
do
path
=
group
.
to_param
control_count
=
ActiveRecord
::
QueryRecorder
.
new
{
described_class
.
find_by_full_path
(
path
)
}.
count
expect
{
described_class
.
find_by_full_path
(
path
).
route
}.
not_to
exceed_all_query_limit
(
control_count
)
end
end
context
'with redirect routes'
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