diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-02 14:22:17 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-04 22:49:42 +0200 |
commit | 6c2de364dd15536d6f004e588e895ad3313533a8 (patch) | |
tree | f6586a79c4c6f2671b3f81242e177a76364e2a48 /app/finders | |
parent | 8a685ca8562a288f0a14f1b5864b97e90fe8c709 (diff) | |
download | gitlab-ce-6c2de364dd15536d6f004e588e895ad3313533a8.tar.gz |
Split up adding ancestors for projects
Diffstat (limited to 'app/finders')
-rw-r--r-- | app/finders/group_descendants_finder.rb | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/app/finders/group_descendants_finder.rb b/app/finders/group_descendants_finder.rb index 920dc4ab201..bde93da3a3e 100644 --- a/app/finders/group_descendants_finder.rb +++ b/app/finders/group_descendants_finder.rb @@ -61,14 +61,19 @@ class GroupDescendantsFinder paginated_projects = paginate_projects_after_groups(subgroups_with_counts) - if params[:filter] - ancestors_for_project_search = ancestors_for_groups(Group.where(id: paginated_projects.select(:namespace_id))) - subgroups_with_counts = ancestors_for_project_search.with_route.select(GROUP_SELECTS) | subgroups_with_counts - end + subgroups_with_counts = add_project_ancestors_when_searching(subgroups_with_counts, paginated_projects) @children = subgroups_with_counts + paginated_projects end + def add_project_ancestors_when_searching(groups, projects) + return groups unless params[:filter] + + project_ancestors = ancestors_for_projects(projects) + .with_route.select(GROUP_SELECTS) + groups | project_ancestors + end + def paginate_projects_after_groups(loaded_subgroups) # We adjust the pagination for projects for the combination with groups: # - We limit the first page (page 0) where we show projects: @@ -138,6 +143,10 @@ class GroupDescendantsFinder .base_and_ancestors.where.not(id: ancestors_for_parent) end + def ancestors_for_projects(projects) + ancestors_for_groups(Group.where(id: projects.select(:namespace_id))) + end + def subgroups return Group.none unless Group.supports_nested_groups? return Group.none unless can?(current_user, :read_group, parent_group) |