diff options
Diffstat (limited to 'app/models/namespaces/traversal/recursive.rb')
-rw-r--r-- | app/models/namespaces/traversal/recursive.rb | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/app/models/namespaces/traversal/recursive.rb b/app/models/namespaces/traversal/recursive.rb index c46cc521735..d74b7883830 100644 --- a/app/models/namespaces/traversal/recursive.rb +++ b/app/models/namespaces/traversal/recursive.rb @@ -15,8 +15,7 @@ module Namespaces # Returns all ancestors, self, and descendants of the current namespace. def self_and_hierarchy - Gitlab::ObjectHierarchy - .new(self.class.where(id: id)) + object_hierarchy(self.class.where(id: id)) .all_objects end @@ -24,38 +23,38 @@ module Namespaces def ancestors return self.class.none unless parent_id - Gitlab::ObjectHierarchy - .new(self.class.where(id: parent_id)) + object_hierarchy(self.class.where(id: parent_id)) .base_and_ancestors end # returns all ancestors upto but excluding the given namespace # when no namespace is given, all ancestors upto the top are returned def ancestors_upto(top = nil, hierarchy_order: nil) - Gitlab::ObjectHierarchy.new(self.class.where(id: id)) + object_hierarchy(self.class.where(id: id)) .ancestors(upto: top, hierarchy_order: hierarchy_order) end def self_and_ancestors(hierarchy_order: nil) return self.class.where(id: id) unless parent_id - Gitlab::ObjectHierarchy - .new(self.class.where(id: id)) + object_hierarchy(self.class.where(id: id)) .base_and_ancestors(hierarchy_order: hierarchy_order) end # Returns all the descendants of the current namespace. def descendants - Gitlab::ObjectHierarchy - .new(self.class.where(parent_id: id)) + object_hierarchy(self.class.where(parent_id: id)) .base_and_descendants end def self_and_descendants - Gitlab::ObjectHierarchy - .new(self.class.where(id: id)) + object_hierarchy(self.class.where(id: id)) .base_and_descendants end + + def object_hierarchy(ancestors_base) + Gitlab::ObjectHierarchy.new(ancestors_base, options: { use_distinct: Feature.enabled?(:use_distinct_in_object_hierarchy, self) }) + end end end end |