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'
This commit is contained in:
Bob Van Landuyt 2017-10-02 07:55:44 +02:00
parent ab5d5b7ece
commit af0b8e0558
3 changed files with 25 additions and 2 deletions

View file

@ -96,9 +96,21 @@ class GroupDescendantsFinder
.search(params[:filter])
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)
ancestors_for_parent = Gitlab::GroupHierarchy.new(Group.where(id: parent_group))
.base_and_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
def subgroups

View file

@ -14,7 +14,8 @@ module GroupDescendant
if parent && parent != hierarchy_top
expand_hierarchy_for_child(parent,
{ parent => hierarchy },
hierarchy_top)
hierarchy_top,
preloaded)
else
hierarchy
end

View file

@ -319,6 +319,16 @@ describe GroupsController do
expect(matched_project_2_json['id']).to eq(matched_project_2.id)
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
2.times { |i| create(:group, :public, parent: public_subgroup, name: "filterme#{i}") }