@@ -27,12 +27,16 @@ def initialize(current_user: nil, parent_group:, params: {})
27
27
end
28
28
29
29
def execute
30
- # The children array might be extended with the ancestors of projects when
31
- # filtering. In that case, take the maximum so the array does not get limited
32
- # Otherwise , allow paginating through all results
30
+ # The children array might be extended with the ancestors of projects and
31
+ # subgroups when filtering. In that case, take the maximum so the array does
32
+ # not get limited otherwise , allow paginating through all results.
33
33
#
34
34
all_required_elements = children
35
- all_required_elements |= ancestors_for_projects if params [ :filter ]
35
+ if params [ :filter ]
36
+ all_required_elements |= ancestors_of_filtered_subgroups
37
+ all_required_elements |= ancestors_of_filtered_projects
38
+ end
39
+
36
40
total_count = [ all_required_elements . size , paginator . total_count ] . max
37
41
38
42
Kaminari . paginate_array ( all_required_elements , total_count : total_count )
@@ -49,8 +53,11 @@ def children
49
53
end
50
54
51
55
def paginator
52
- @paginator ||= Gitlab ::MultiCollectionPaginator . new ( subgroups , projects ,
53
- per_page : params [ :per_page ] )
56
+ @paginator ||= Gitlab ::MultiCollectionPaginator . new (
57
+ subgroups ,
58
+ projects . with_route ,
59
+ per_page : params [ :per_page ]
60
+ )
54
61
end
55
62
56
63
def direct_child_groups
@@ -94,15 +101,21 @@ def subgroups_matching_filter
94
101
#
95
102
# So when searching 'project', on the 'subgroup' page we want to preload
96
103
# 'nested-group' but not 'subgroup' or 'root'
97
- def ancestors_for_groups ( base_for_ancestors )
98
- Gitlab ::GroupHierarchy . new ( base_for_ancestors )
104
+ def ancestors_of_groups ( base_for_ancestors )
105
+ group_ids = base_for_ancestors . except ( :select , :sort ) . select ( :id )
106
+ Gitlab ::GroupHierarchy . new ( Group . where ( id : group_ids ) )
99
107
. base_and_ancestors ( upto : parent_group . id )
100
108
end
101
109
102
- def ancestors_for_projects
110
+ def ancestors_of_filtered_projects
103
111
projects_to_load_ancestors_of = projects . where . not ( namespace : parent_group )
104
112
groups_to_load_ancestors_of = Group . where ( id : projects_to_load_ancestors_of . select ( :namespace_id ) )
105
- ancestors_for_groups ( groups_to_load_ancestors_of )
113
+ ancestors_of_groups ( groups_to_load_ancestors_of )
114
+ . with_selects_for_list ( archived : params [ :archived ] )
115
+ end
116
+
117
+ def ancestors_of_filtered_subgroups
118
+ ancestors_of_groups ( subgroups )
106
119
. with_selects_for_list ( archived : params [ :archived ] )
107
120
end
108
121
@@ -112,7 +125,7 @@ def subgroups
112
125
# When filtering subgroups, we want to find all matches withing the tree of
113
126
# descendants to show to the user
114
127
groups = if params [ :filter ]
115
- ancestors_for_groups ( subgroups_matching_filter )
128
+ subgroups_matching_filter
116
129
else
117
130
direct_child_groups
118
131
end
@@ -121,8 +134,10 @@ def subgroups
121
134
end
122
135
123
136
def direct_child_projects
124
- GroupProjectsFinder . new ( group : parent_group , current_user : current_user , params : params )
125
- . execute
137
+ GroupProjectsFinder . new ( group : parent_group ,
138
+ current_user : current_user ,
139
+ options : { only_owned : true } ,
140
+ params : params ) . execute
126
141
end
127
142
128
143
# Finds all projects nested under `parent_group` or any of its descendant
0 commit comments