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
aee5691d
Commit
aee5691d
authored
Oct 10, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't load unneeded elements in GroupsController#show
parent
3fe7f31a
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
68 additions
and
70 deletions
+68
-70
app/controllers/groups_controller.rb
app/controllers/groups_controller.rb
+5
-18
app/finders/group_descendants_finder.rb
app/finders/group_descendants_finder.rb
+2
-6
app/views/groups/show.html.haml
app/views/groups/show.html.haml
+1
-1
spec/controllers/groups_controller_spec.rb
spec/controllers/groups_controller_spec.rb
+44
-45
spec/finders/group_descendants_finder_spec.rb
spec/finders/group_descendants_finder_spec.rb
+16
-0
No files found.
app/controllers/groups_controller.rb
View file @
aee5691d
...
@@ -45,13 +45,14 @@ class GroupsController < Groups::ApplicationController
...
@@ -45,13 +45,14 @@ class GroupsController < Groups::ApplicationController
end
end
def
show
def
show
setup_children
(
@group
)
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
format
.
html
do
@has_children
=
GroupDescendantsFinder
.
new
(
current_user:
current_user
,
parent_group:
@group
,
params:
params
).
has_children?
end
format
.
atom
do
format
.
atom
do
setup_projects
load_events
load_events
render
layout:
'xml.atom'
render
layout:
'xml.atom'
end
end
...
@@ -126,20 +127,6 @@ class GroupsController < Groups::ApplicationController
...
@@ -126,20 +127,6 @@ class GroupsController < Groups::ApplicationController
@children
=
@children
.
page
(
params
[
:page
])
@children
=
@children
.
page
(
params
[
:page
])
end
end
def
setup_projects
set_non_archived_param
params
[
:sort
]
||=
'latest_activity_desc'
@sort
=
params
[
:sort
]
options
=
{}
options
[
:only_owned
]
=
true
if
params
[
:shared
]
==
'0'
options
[
:only_shared
]
=
true
if
params
[
:shared
]
==
'1'
@projects
=
GroupProjectsFinder
.
new
(
params:
params
,
group:
group
,
options:
options
,
current_user:
current_user
).
execute
@projects
=
@projects
.
includes
(
:namespace
)
@projects
=
@projects
.
page
(
params
[
:page
])
if
params
[
:name
].
blank?
end
def
authorize_create_group!
def
authorize_create_group!
allowed
=
if
params
[
:parent_id
].
present?
allowed
=
if
params
[
:parent_id
].
present?
parent
=
Group
.
find_by
(
id:
params
[
:parent_id
])
parent
=
Group
.
find_by
(
id:
params
[
:parent_id
])
...
...
app/finders/group_descendants_finder.rb
View file @
aee5691d
...
@@ -19,12 +19,8 @@ class GroupDescendantsFinder
...
@@ -19,12 +19,8 @@ class GroupDescendantsFinder
Kaminari
.
paginate_array
(
all_required_elements
,
total_count:
total_count
)
Kaminari
.
paginate_array
(
all_required_elements
,
total_count:
total_count
)
end
end
def
subgroup_count
def
has_children?
@subgroup_count
||=
subgroups
.
count
projects
.
any?
||
subgroups
.
any?
end
def
project_count
@project_count
||=
projects
.
count
end
end
private
private
...
...
app/views/groups/show.html.haml
View file @
aee5691d
...
@@ -39,7 +39,7 @@
...
@@ -39,7 +39,7 @@
-
else
-
else
=
link_to
new_project_label
,
new_project_path
(
namespace_id:
@group
.
id
),
class:
"btn btn-success"
=
link_to
new_project_label
,
new_project_path
(
namespace_id:
@group
.
id
),
class:
"btn btn-success"
-
if
params
[
:filter
].
blank?
&&
@children
.
empty?
-
if
params
[
:filter
].
blank?
&&
!
@has_children
=
render
"shared/groups/empty_state"
=
render
"shared/groups/empty_state"
-
else
-
else
=
render
"children"
,
children:
@children
,
group:
@group
=
render
"children"
,
children:
@children
,
group:
@group
spec/controllers/groups_controller_spec.rb
View file @
aee5691d
...
@@ -150,51 +150,6 @@ describe GroupsController do
...
@@ -150,51 +150,6 @@ describe GroupsController do
end
end
end
end
describe
'GET #show'
do
context
'pagination'
do
let
(
:per_page
)
{
3
}
before
do
allow
(
Kaminari
.
config
).
to
receive
(
:default_per_page
).
and_return
(
per_page
)
end
context
'with only projects'
do
let!
(
:other_project
)
{
create
(
:project
,
:public
,
namespace:
group
)
}
let!
(
:first_page_projects
)
{
create_list
(
:project
,
per_page
,
:public
,
namespace:
group
)
}
it
'has projects on the first page'
do
get
:show
,
id:
group
.
to_param
,
sort:
'id_desc'
expect
(
assigns
(
:children
)).
to
contain_exactly
(
*
first_page_projects
)
end
it
'has projects on the second page'
do
get
:show
,
id:
group
.
to_param
,
sort:
'id_desc'
,
page:
2
expect
(
assigns
(
:children
)).
to
contain_exactly
(
other_project
)
end
end
context
'with subgroups and projects'
,
:nested_groups
do
let!
(
:first_page_subgroups
)
{
create_list
(
:group
,
per_page
,
:public
,
parent:
group
)
}
let!
(
:other_subgroup
)
{
create
(
:group
,
:public
,
parent:
group
)
}
let!
(
:next_page_projects
)
{
create_list
(
:project
,
per_page
,
:public
,
namespace:
group
)
}
it
'contains all subgroups'
do
get
:children
,
id:
group
.
to_param
,
sort:
'id_asc'
,
format: :json
expect
(
assigns
(
:children
)).
to
contain_exactly
(
*
first_page_subgroups
)
end
it
'contains the project and group on the second page'
do
get
:children
,
id:
group
.
to_param
,
sort:
'id_asc'
,
page:
2
,
format: :json
expect
(
assigns
(
:children
)).
to
contain_exactly
(
other_subgroup
,
*
next_page_projects
.
take
(
per_page
-
1
))
end
end
end
end
describe
'GET #children'
do
describe
'GET #children'
do
context
'for projects'
do
context
'for projects'
do
let!
(
:public_project
)
{
create
(
:project
,
:public
,
namespace:
group
)
}
let!
(
:public_project
)
{
create
(
:project
,
:public
,
namespace:
group
)
}
...
@@ -420,6 +375,50 @@ describe GroupsController do
...
@@ -420,6 +375,50 @@ describe GroupsController do
end
end
end
end
end
end
context
'pagination'
do
let
(
:per_page
)
{
3
}
before
do
allow
(
Kaminari
.
config
).
to
receive
(
:default_per_page
).
and_return
(
per_page
)
end
context
'with only projects'
do
let!
(
:other_project
)
{
create
(
:project
,
:public
,
namespace:
group
)
}
let!
(
:first_page_projects
)
{
create_list
(
:project
,
per_page
,
:public
,
namespace:
group
)
}
it
'has projects on the first page'
do
get
:children
,
id:
group
.
to_param
,
sort:
'id_desc'
,
format: :json
expect
(
assigns
(
:children
)).
to
contain_exactly
(
*
first_page_projects
)
end
it
'has projects on the second page'
do
get
:children
,
id:
group
.
to_param
,
sort:
'id_desc'
,
page:
2
,
format: :json
expect
(
assigns
(
:children
)).
to
contain_exactly
(
other_project
)
end
end
context
'with subgroups and projects'
,
:nested_groups
do
let!
(
:first_page_subgroups
)
{
create_list
(
:group
,
per_page
,
:public
,
parent:
group
)
}
let!
(
:other_subgroup
)
{
create
(
:group
,
:public
,
parent:
group
)
}
let!
(
:next_page_projects
)
{
create_list
(
:project
,
per_page
,
:public
,
namespace:
group
)
}
it
'contains all subgroups'
do
get
:children
,
id:
group
.
to_param
,
sort:
'id_asc'
,
format: :json
expect
(
assigns
(
:children
)).
to
contain_exactly
(
*
first_page_subgroups
)
end
it
'contains the project and group on the second page'
do
get
:children
,
id:
group
.
to_param
,
sort:
'id_asc'
,
page:
2
,
format: :json
expect
(
assigns
(
:children
)).
to
contain_exactly
(
other_subgroup
,
*
next_page_projects
.
take
(
per_page
-
1
))
end
end
end
end
end
describe
'GET #issues'
do
describe
'GET #issues'
do
...
...
spec/finders/group_descendants_finder_spec.rb
View file @
aee5691d
...
@@ -12,6 +12,22 @@ describe GroupDescendantsFinder do
...
@@ -12,6 +12,22 @@ describe GroupDescendantsFinder do
group
.
add_owner
(
user
)
group
.
add_owner
(
user
)
end
end
describe
'#has_children?'
do
it
'is true when there are projects'
do
create
(
:project
,
namespace:
group
)
expect
(
finder
.
has_children?
).
to
be_truthy
end
context
'when there are subgroups'
,
:nested_groups
do
it
'is true when there are projects'
do
create
(
:group
,
parent:
group
)
expect
(
finder
.
has_children?
).
to
be_truthy
end
end
end
describe
'#execute'
do
describe
'#execute'
do
it
'includes projects'
do
it
'includes projects'
do
project
=
create
(
:project
,
namespace:
group
)
project
=
create
(
:project
,
namespace:
group
)
...
...
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