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
Boxiang Sun
gitlab-ce
Commits
79cc3c8e
Commit
79cc3c8e
authored
Sep 10, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Limit the amount of queries per row
parent
bb5187bb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
13 deletions
+84
-13
app/finders/group_children_finder.rb
app/finders/group_children_finder.rb
+2
-2
app/serializers/group_child_entity.rb
app/serializers/group_child_entity.rb
+3
-5
spec/controllers/groups_controller_spec.rb
spec/controllers/groups_controller_spec.rb
+79
-6
No files found.
app/finders/group_children_finder.rb
View file @
79cc3c8e
...
...
@@ -65,7 +65,7 @@ class GroupChildrenFinder
base_groups
end
groups
=
groups
groups
.
sort
(
params
[
:sort
])
groups
.
sort
(
params
[
:sort
])
.
includes
(
:route
)
end
def
base_projects
...
...
@@ -86,6 +86,6 @@ class GroupChildrenFinder
else
base_projects
end
projects
.
sort
(
params
[
:sort
])
projects
.
sort
(
params
[
:sort
])
.
includes
(
:route
,
:namespace
)
end
end
app/serializers/group_child_entity.rb
View file @
79cc3c8e
...
...
@@ -32,11 +32,9 @@ class GroupChildEntity < Grape::Entity
end
def
permission
if
project?
object
.
project_members
.
find_by
(
user_id:
request
.
current_user
)
&
.
human_access
else
object
.
group_members
.
find_by
(
user_id:
request
.
current_user
)
&
.
human_access
end
return
unless
request
&
.
current_user
request
.
current_user
.
members
.
find_by
(
source:
object
)
&
.
human_access
end
# Project only attributes
...
...
spec/controllers/groups_controller_spec.rb
View file @
79cc3c8e
...
...
@@ -226,14 +226,10 @@ describe GroupsController do
end
context
'filtering children'
do
def
get_filtered_list
get
:children
,
id:
group
.
to_param
,
filter:
'filter'
,
format: :json
end
it
'expands the tree for matching projects'
do
project
=
create
(
:project
,
:public
,
namespace:
public_subgroup
,
name:
'filterme'
)
get
_filtered_list
get
:children
,
id:
group
.
to_param
,
filter:
'filter'
,
format: :json
group_json
=
json_response
.
first
project_json
=
group_json
[
'children'
].
first
...
...
@@ -245,7 +241,7 @@ describe GroupsController do
it
'expands the tree for matching subgroups'
do
matched_group
=
create
(
:group
,
:public
,
parent:
public_subgroup
,
name:
'filterme'
)
get
_filtered_list
get
:children
,
id:
group
.
to_param
,
filter:
'filter'
,
format: :json
group_json
=
json_response
.
first
matched_group_json
=
group_json
[
'children'
].
first
...
...
@@ -254,6 +250,83 @@ describe GroupsController do
expect
(
matched_group_json
[
'id'
]).
to
eq
(
matched_group
.
id
)
end
end
context
'queries per rendered element'
do
# The expected extra queries for the rendered group are:
# 1. Count of memberships of the group
# 2. Count of visible projects in the element
# 3. Count of visible subgroups in the element
let
(
:expected_queries_per_group
)
{
3
}
let
(
:expected_queries_per_project
)
{
0
}
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
_new_group
=
create
(
:group
,
:public
,
parent:
group
)
expect
{
get_list
}.
not_to
exceed_query_limit
(
control_count
+
expected_queries_per_group
)
end
it
'queries the expected amount for a project row'
do
control_count
=
ActiveRecord
::
QueryRecorder
.
new
{
get_list
}.
count
_new_project
=
create
(
:project
,
:public
,
namespace:
group
)
expect
{
get_list
}.
not_to
exceed_query_limit
(
control_count
+
expected_queries_per_project
)
end
context
'when rendering hierarchies'
do
def
get_filtered_list
get
:children
,
id:
group
.
to_param
,
filter:
'filter'
,
format: :json
end
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
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
)
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
create
(
:group
,
:public
,
parent:
public_subgroup
,
name:
'filterme2'
)
expect
{
get_filtered_list
}.
not_to
exceed_query_limit
(
control_count
+
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
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
)
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
create
(
:project
,
:public
,
namespace:
public_subgroup
,
name:
'filterme2'
)
expect
{
get_filtered_list
}.
not_to
exceed_query_limit
(
control_count
+
expected_queries_per_project
)
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