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
20a08965
Commit
20a08965
authored
Sep 14, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[WIP] improve number of queries when rendering a hierarchy
parent
ea4e17e2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
15 deletions
+22
-15
app/finders/group_children_finder.rb
app/finders/group_children_finder.rb
+3
-3
spec/controllers/groups_controller_spec.rb
spec/controllers/groups_controller_spec.rb
+19
-12
No files found.
app/finders/group_children_finder.rb
View file @
20a08965
...
...
@@ -38,7 +38,7 @@ class GroupChildrenFinder
private
def
children
@children
||=
subgroups
+
projects
@children
||=
subgroups
.
with_route
.
includes
(
:route
,
:parent
)
+
projects
.
with_route
.
includes
(
:route
,
:namespace
)
end
def
base_groups
...
...
@@ -64,7 +64,7 @@ class GroupChildrenFinder
else
base_groups
end
groups
.
sort
(
params
[
:sort
])
.
includes
(
:route
)
groups
.
sort
(
params
[
:sort
])
end
def
base_projects
...
...
@@ -85,6 +85,6 @@ class GroupChildrenFinder
else
base_projects
end
projects
.
sort
(
params
[
:sort
])
.
includes
(
:route
,
:namespace
)
projects
.
sort
(
params
[
:sort
])
end
end
spec/controllers/groups_controller_spec.rb
View file @
20a08965
...
...
@@ -300,22 +300,28 @@ describe GroupsController do
let
(
:expected_queries_per_group
)
{
5
}
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
get
:children
,
id:
group
.
to_param
,
format: :json
end
it
'queries the expected amount for a group row'
do
control
_count
=
ActiveRecord
::
QueryRecorder
.
new
{
get_list
}.
count
control
=
ActiveRecord
::
QueryRecorder
.
new
{
get_list
}
_new_group
=
create
(
:group
,
:public
,
parent:
group
)
expect
{
get_list
}.
not_to
exceed_query_limit
(
control
_count
+
expected_queries_per_group
)
expect
{
get_list
}.
not_to
exceed_query_limit
(
control
).
with_threshold
(
expected_queries_per_group
)
end
it
'queries the expected amount for a project row'
do
control
_count
=
ActiveRecord
::
QueryRecorder
.
new
{
get_list
}.
count
control
=
ActiveRecord
::
QueryRecorder
.
new
{
get_list
}
_new_project
=
create
(
:project
,
:public
,
namespace:
group
)
expect
{
get_list
}.
not_to
exceed_query_limit
(
control
_count
+
expected_queries_per_project
)
expect
{
get_list
}.
not_to
exceed_query_limit
(
control
).
with_threshold
(
expected_queries_per_project
)
end
context
'when rendering hierarchies'
do
...
...
@@ -326,41 +332,42 @@ describe GroupsController do
it
'queries the expected amount when nested rows are rendered for a group'
do
matched_group
=
create
(
:group
,
:public
,
parent:
public_subgroup
,
name:
'filterme'
)
control
_count
=
ActiveRecord
::
QueryRecorder
.
new
{
get_filtered_list
}.
count
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
_count
+
expected_queries_per_group
)
expect
{
get_filtered_list
}.
not_to
exceed_query_limit
(
control
).
with_threshold
(
expected_queries_per_group
)
end
it
'queries the expected amount when a new group match is added'
do
create
(
:group
,
:public
,
parent:
public_subgroup
,
name:
'filterme'
)
control_count
=
ActiveRecord
::
QueryRecorder
.
new
{
get_filtered_list
}.
count
control
=
ActiveRecord
::
QueryRecorder
.
new
{
get_filtered_list
}
create
(
:group
,
:public
,
parent:
public_subgroup
,
name:
'filterme2'
)
expect
{
get_filtered_list
}.
not_to
exceed_query_limit
(
control
_count
+
expected_queries_per_group
)
expect
{
get_filtered_list
}.
not_to
exceed_query_limit
(
control
).
with_threshold
(
expected_queries_per_group
)
end
it
'queries the expected amount when nested rows are rendered for a project'
do
matched_project
=
create
(
:project
,
:public
,
namespace:
public_subgroup
,
name:
'filterme'
)
control
_count
=
ActiveRecord
::
QueryRecorder
.
new
{
get_filtered_list
}.
count
control
=
ActiveRecord
::
QueryRecorder
.
new
{
get_filtered_list
}
nested_group
=
create
(
:group
,
:public
,
parent:
public_subgroup
)
matched_project
.
update!
(
namespace:
nested_group
)
expect
{
get_filtered_list
}.
not_to
exceed_query_limit
(
control
_count
+
expected_queries_per_group
)
expect
{
get_filtered_list
}.
not_to
exceed_query_limit
(
control
).
with_threshold
(
expected_queries_per_group
)
end
it
'queries the expected amount when a new project match is added'
do
create
(
:project
,
:public
,
namespace:
public_subgroup
,
name:
'filterme'
)
control
_count
=
ActiveRecord
::
QueryRecorder
.
new
{
get_filtered_list
}.
count
control
=
ActiveRecord
::
QueryRecorder
.
new
{
get_filtered_list
}
create
(
:project
,
:public
,
namespace:
public_subgroup
,
name:
'filterme2'
)
expect
{
get_filtered_list
}.
not_to
exceed_query_limit
(
control
_count
+
expected_queries_per_project
)
expect
{
get_filtered_list
}.
not_to
exceed_query_limit
(
control
).
with_threshold
(
expected_queries_per_project
)
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