diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-10 15:11:55 +0300 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-10 17:54:28 +0300 |
commit | aee5691db3ec411c242e050aaa11ebb44f07f164 (patch) | |
tree | 1bacabb4632b3d90701729d32cbaf41ddeb51c14 /app | |
parent | 3fe7f31ac047e1b9ba3ae53cea17012ce2f7f3e7 (diff) |
Don't load unneeded elements in GroupsController#show
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/groups_controller.rb | 23 | ||||
-rw-r--r-- | app/finders/group_descendants_finder.rb | 8 | ||||
-rw-r--r-- | app/views/groups/show.html.haml | 2 |
3 files changed, 8 insertions, 25 deletions
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 8c2053e8574..a24a0056a30 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -45,13 +45,14 @@ class GroupsController < Groups::ApplicationController end def show - setup_children(@group) - 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 - setup_projects load_events render layout: 'xml.atom' end @@ -126,20 +127,6 @@ class GroupsController < Groups::ApplicationController @children = @children.page(params[:page]) 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! allowed = if params[:parent_id].present? parent = Group.find_by(id: params[:parent_id]) diff --git a/app/finders/group_descendants_finder.rb b/app/finders/group_descendants_finder.rb index 3f231bd8b10..cdd18b89525 100644 --- a/app/finders/group_descendants_finder.rb +++ b/app/finders/group_descendants_finder.rb @@ -19,12 +19,8 @@ class GroupDescendantsFinder Kaminari.paginate_array(all_required_elements, total_count: total_count) end - def subgroup_count - @subgroup_count ||= subgroups.count - end - - def project_count - @project_count ||= projects.count + def has_children? + projects.any? || subgroups.any? end private diff --git a/app/views/groups/show.html.haml b/app/views/groups/show.html.haml index 75f7473d1ef..6a7d8e84636 100644 --- a/app/views/groups/show.html.haml +++ b/app/views/groups/show.html.haml @@ -39,7 +39,7 @@ - else = 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" - else = render "children", children: @children, group: @group |