Commit af0b8e05 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Only preload ancestors for search results in the specified parent

When filtering we want all to preload all the ancestors upto the specified
parent group.

- root
  - subgroup
    - nested-group
      - project

So when searching 'project', on the 'subgroup' page we want to preload
'nested-group' but not 'subgroup' or 'root'
parent ab5d5b7e
...@@ -96,9 +96,21 @@ class GroupDescendantsFinder ...@@ -96,9 +96,21 @@ class GroupDescendantsFinder
.search(params[:filter]) .search(params[:filter])
end end
# When filtering we want all to preload all the ancestors upto the specified
# parent group.
#
# - root
# - subgroup
# - nested-group
# - project
#
# So when searching 'project', on the 'subgroup' page we want to preload
# 'nested-group' but not 'subgroup' or 'root'
def ancestors_for_groups(base_for_ancestors) def ancestors_for_groups(base_for_ancestors)
ancestors_for_parent = Gitlab::GroupHierarchy.new(Group.where(id: parent_group))
.base_and_ancestors
Gitlab::GroupHierarchy.new(base_for_ancestors) Gitlab::GroupHierarchy.new(base_for_ancestors)
.base_and_ancestors.where.not(id: parent_group) .base_and_ancestors.where.not(id: ancestors_for_parent)
end end
def subgroups def subgroups
......
...@@ -14,7 +14,8 @@ module GroupDescendant ...@@ -14,7 +14,8 @@ module GroupDescendant
if parent && parent != hierarchy_top if parent && parent != hierarchy_top
expand_hierarchy_for_child(parent, expand_hierarchy_for_child(parent,
{ parent => hierarchy }, { parent => hierarchy },
hierarchy_top) hierarchy_top,
preloaded)
else else
hierarchy hierarchy
end end
......
...@@ -319,6 +319,16 @@ describe GroupsController do ...@@ -319,6 +319,16 @@ describe GroupsController do
expect(matched_project_2_json['id']).to eq(matched_project_2.id) expect(matched_project_2_json['id']).to eq(matched_project_2.id)
end end
it 'expands the tree upto a specified parent' do
subgroup = create(:group, :public, parent: group)
l2_subgroup = create(:group, :public, parent: subgroup)
create(:project, :public, namespace: l2_subgroup, name: 'test')
get :children, id: subgroup.to_param, filter: 'test', format: :json
expect(response).to have_http_status(200)
end
it 'includes pagination headers' do it 'includes pagination headers' do
2.times { |i| create(:group, :public, parent: public_subgroup, name: "filterme#{i}") } 2.times { |i| create(:group, :public, parent: public_subgroup, name: "filterme#{i}") }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment