diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-21 02:50:22 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-21 02:50:22 +0300 |
commit | 9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch) | |
tree | 70467ae3692a0e35e5ea56bcb803eb512a10bedb /app/models/namespaces/traversal/recursive.rb | |
parent | 4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff) |
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'app/models/namespaces/traversal/recursive.rb')
-rw-r--r-- | app/models/namespaces/traversal/recursive.rb | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/app/models/namespaces/traversal/recursive.rb b/app/models/namespaces/traversal/recursive.rb index d74b7883830..409438f53d2 100644 --- a/app/models/namespaces/traversal/recursive.rb +++ b/app/models/namespaces/traversal/recursive.rb @@ -6,10 +6,14 @@ module Namespaces extend ActiveSupport::Concern def root_ancestor - return self if persisted? && parent_id.nil? + return self if parent.nil? - strong_memoize(:root_ancestor) do - self_and_ancestors.reorder(nil).find_by(parent_id: nil) + if persisted? + strong_memoize(:root_ancestor) do + self_and_ancestors.reorder(nil).find_by(parent_id: nil) + end + else + parent.root_ancestor end end @@ -18,6 +22,7 @@ module Namespaces object_hierarchy(self.class.where(id: id)) .all_objects end + alias_method :recursive_self_and_hierarchy, :self_and_hierarchy # Returns all the ancestors of the current namespaces. def ancestors @@ -26,6 +31,7 @@ module Namespaces object_hierarchy(self.class.where(id: parent_id)) .base_and_ancestors end + alias_method :recursive_ancestors, :ancestors # returns all ancestors upto but excluding the given namespace # when no namespace is given, all ancestors upto the top are returned @@ -40,17 +46,20 @@ module Namespaces object_hierarchy(self.class.where(id: id)) .base_and_ancestors(hierarchy_order: hierarchy_order) end + alias_method :recursive_self_and_ancestors, :self_and_ancestors # Returns all the descendants of the current namespace. def descendants object_hierarchy(self.class.where(parent_id: id)) .base_and_descendants end + alias_method :recursive_descendants, :descendants def self_and_descendants object_hierarchy(self.class.where(id: id)) .base_and_descendants end + alias_method :recursive_self_and_descendants, :self_and_descendants def object_hierarchy(ancestors_base) Gitlab::ObjectHierarchy.new(ancestors_base, options: { use_distinct: Feature.enabled?(:use_distinct_in_object_hierarchy, self) }) |