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
29df1ce8
Commit
29df1ce8
authored
Sep 19, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve number of queries
And document what extra queries are still being performed.
parent
22aa0344
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
26 deletions
+26
-26
app/finders/group_descendants_finder.rb
app/finders/group_descendants_finder.rb
+1
-1
spec/controllers/groups_controller_spec.rb
spec/controllers/groups_controller_spec.rb
+25
-25
No files found.
app/finders/group_descendants_finder.rb
View file @
29df1ce8
...
@@ -38,7 +38,7 @@ class GroupDescendantsFinder
...
@@ -38,7 +38,7 @@ class GroupDescendantsFinder
private
private
def
children
def
children
@children
||=
subgroups
.
with_route
.
includes
(
:parent
)
+
projects
.
with_route
.
includes
(
:namespace
)
@children
||=
subgroups
.
with_route
.
includes
(
parent:
[
:route
,
:parent
])
+
projects
.
with_route
.
includes
(
namespace:
[
:route
,
:parent
]
)
end
end
def
direct_child_groups
def
direct_child_groups
...
...
spec/controllers/groups_controller_spec.rb
View file @
29df1ce8
...
@@ -304,26 +304,18 @@ describe GroupsController do
...
@@ -304,26 +304,18 @@ describe GroupsController do
context
'queries per rendered element'
,
:request_store
do
context
'queries per rendered element'
,
:request_store
do
# The expected extra queries for the rendered group are:
# The expected extra queries for the rendered group are:
# 1. Count of memberships of the group
# 1. Count of visible projects in the element
# 2. Count of visible projects in the element
# 2. Count of visible subgroups in the element
# 3. Count of visible subgroups in the element
let
(
:expected_queries_per_group
)
{
2
}
# 4. Every parent
# 5. The route for a parent
let
(
:expected_queries_per_group
)
{
5
}
let
(
:expected_queries_per_project
)
{
0
}
let
(
:expected_queries_per_project
)
{
0
}
before
do
# Create the group before anything so it doesn't get tracked by the
# query recorder
group
end
def
get_list
def
get_list
get
:children
,
id:
group
.
to_param
,
format: :json
get
:children
,
id:
group
.
to_param
,
format: :json
end
end
it
'queries the expected amount for a group row'
do
it
'queries the expected amount for a group row'
do
control
=
ActiveRecord
::
QueryRecorder
.
new
{
get_list
}
control
=
ActiveRecord
::
QueryRecorder
.
new
{
get_list
}
_new_group
=
create
(
:group
,
:public
,
parent:
group
)
_new_group
=
create
(
:group
,
:public
,
parent:
group
)
expect
{
get_list
}.
not_to
exceed_query_limit
(
control
).
with_threshold
(
expected_queries_per_group
)
expect
{
get_list
}.
not_to
exceed_query_limit
(
control
).
with_threshold
(
expected_queries_per_group
)
...
@@ -337,18 +329,26 @@ describe GroupsController do
...
@@ -337,18 +329,26 @@ describe GroupsController do
end
end
context
'when rendering hierarchies'
do
context
'when rendering hierarchies'
do
# Extra queries per group when rendering a hierarchy:
# The route and the namespace are `included` for all matched elements
# But the parent's above those are not, so there's 2 extra queries per
# nested level:
# 1. Loading the parent that wasn't loaded yet
# 2. Loading the route for that parent.
let
(
:extra_queries_per_nested_level
)
{
expected_queries_per_group
+
2
}
def
get_filtered_list
def
get_filtered_list
get
:children
,
id:
group
.
to_param
,
filter:
'filter'
,
format: :json
get
:children
,
id:
group
.
to_param
,
filter:
'filter'
,
format: :json
end
end
it
'queries the expected amount when nested rows are
render
ed for a group'
do
it
'queries the expected amount when nested rows are
increas
ed for a group'
do
matched_group
=
create
(
:group
,
:public
,
parent:
public_sub
group
,
name:
'filterme'
)
matched_group
=
create
(
:group
,
:public
,
parent:
group
,
name:
'filterme'
)
control
=
ActiveRecord
::
QueryRecorder
.
new
{
get_filtered_list
}
control
=
ActiveRecord
::
QueryRecorder
.
new
{
get_filtered_list
}
nested_group
=
create
(
:group
,
:public
,
parent:
public_subgroup
)
matched_group
.
update!
(
parent:
nested_group
)
expect
{
get_filtered_list
}.
not_to
exceed_query_limit
(
control
).
with_threshold
(
expected_queries_per_group
)
matched_group
.
update!
(
parent:
public_subgroup
)
expect
{
get_filtered_list
}.
not_to
exceed_query_limit
(
control
).
with_threshold
(
extra_queries_per_nested_level
)
end
end
it
'queries the expected amount when a new group match is added'
do
it
'queries the expected amount when a new group match is added'
do
...
@@ -358,18 +358,17 @@ describe GroupsController do
...
@@ -358,18 +358,17 @@ describe GroupsController do
create
(
:group
,
:public
,
parent:
public_subgroup
,
name:
'filterme2'
)
create
(
:group
,
:public
,
parent:
public_subgroup
,
name:
'filterme2'
)
expect
{
get_filtered_list
}.
not_to
exceed_query_limit
(
control
).
with_threshold
(
ex
pected_queries_per_group
)
expect
{
get_filtered_list
}.
not_to
exceed_query_limit
(
control
).
with_threshold
(
ex
tra_queries_per_nested_level
)
end
end
it
'queries the expected amount when nested rows are
render
ed for a project'
do
it
'queries the expected amount when nested rows are
increas
ed for a project'
do
matched_project
=
create
(
:project
,
:public
,
namespace:
public_sub
group
,
name:
'filterme'
)
matched_project
=
create
(
:project
,
:public
,
namespace:
group
,
name:
'filterme'
)
control
=
ActiveRecord
::
QueryRecorder
.
new
{
get_filtered_list
}
control
=
ActiveRecord
::
QueryRecorder
.
new
{
get_filtered_list
}
nested_group
=
create
(
:group
,
:public
,
parent:
public_subgroup
)
matched_project
.
update!
(
namespace:
public_subgroup
)
matched_project
.
update!
(
namespace:
nested_group
)
expect
{
get_filtered_list
}.
not_to
exceed_query_limit
(
control
).
with_threshold
(
ex
pected_queries_per_group
)
expect
{
get_filtered_list
}.
not_to
exceed_query_limit
(
control
).
with_threshold
(
ex
tra_queries_per_nested_level
)
end
end
it
'queries the expected amount when a new project match is added'
do
it
'queries the expected amount when a new project match is added'
do
...
@@ -377,9 +376,10 @@ describe GroupsController do
...
@@ -377,9 +376,10 @@ describe GroupsController do
control
=
ActiveRecord
::
QueryRecorder
.
new
{
get_filtered_list
}
control
=
ActiveRecord
::
QueryRecorder
.
new
{
get_filtered_list
}
create
(
:project
,
:public
,
namespace:
public_subgroup
,
name:
'filterme2'
)
nested_group
=
create
(
:group
,
:public
,
parent:
group
)
create
(
:project
,
:public
,
namespace:
nested_group
,
name:
'filterme2'
)
expect
{
get_filtered_list
}.
not_to
exceed_query_limit
(
control
).
with_threshold
(
ex
pected_queries_per_project
)
expect
{
get_filtered_list
}.
not_to
exceed_query_limit
(
control
).
with_threshold
(
ex
tra_queries_per_nested_level
)
end
end
end
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