Skip to content
Snippets Groups Projects

Traversal ids queries

Closed Alex Pooley requested to merge traversal-ids-queries into master
7 unresolved threads
Compare and Show latest version
3 files
+ 15
11
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -7,16 +7,16 @@ module GroupDescendant
@@ -7,16 +7,16 @@ module GroupDescendant
# > project.hierarchy
# > project.hierarchy
# => { parent_group => { child_group => project } }
# => { parent_group => { child_group => project } }
def hierarchy(hierarchy_top = nil, preloaded = nil)
def hierarchy(hierarchy_top = nil, preloaded = nil)
if self.is_a?(Group) && Feature.enabled?(:linear_groups, root_ancestor)
# There is a quirk with the recursive ancestor_upto search where the search continues
# There is a quirk with the recursive ancestor_upto search where the search continues
# until the upto node is reached, or we run out of ancestors to recurse through.
# until the upto node is reached, or we run out of ancestors to recurse through.
# If upto is not an ancestor then the whole ancestor chain is returned. Linear traversal
# If upto is not an ancestor then the whole ancestor chain is returned. Linear traversal
# does not work in this way so we have to drop back to recursive search for now.
# does not work in this way so we have to drop back to recursive search for now.
preloaded ||= if self.is_a?(Group) && Feature.enabled?(:linear_groups, root_ancestor)
preloaded ||= Gitlab::ObjectHierarchy.new(self.class.where(id: id))
Gitlab::ObjectHierarchy.new(self.class.where(id: id)).ancestors(upto: hierarchy_top)
.ancestors(upto: hierarchy_top)
else
else
ancestors_upto(hierarchy_top)
preloaded ||= ancestors_upto(hierarchy_top)
end
end
expand_hierarchy_for_child(self, self, hierarchy_top, preloaded)
expand_hierarchy_for_child(self, self, hierarchy_top, preloaded)
end
end
Loading