Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/namespaces/traversal/linear.rb')
-rw-r--r--app/models/namespaces/traversal/linear.rb30
1 files changed, 28 insertions, 2 deletions
diff --git a/app/models/namespaces/traversal/linear.rb b/app/models/namespaces/traversal/linear.rb
index d0281f4d974..e4c343bc89f 100644
--- a/app/models/namespaces/traversal/linear.rb
+++ b/app/models/namespaces/traversal/linear.rb
@@ -64,6 +64,13 @@ module Namespaces
traversal_ids.present?
end
+ def use_traversal_ids_for_ancestors?
+ return false unless use_traversal_ids?
+ return false unless Feature.enabled?(:use_traversal_ids_for_ancestors, root_ancestor, default_enabled: :yaml)
+
+ traversal_ids.present?
+ end
+
def root_ancestor
return super if parent.nil?
return super unless persisted?
@@ -95,14 +102,33 @@ module Namespaces
end
def ancestors(hierarchy_order: nil)
- return super() unless use_traversal_ids?
- return super() unless Feature.enabled?(:use_traversal_ids_for_ancestors, root_ancestor, default_enabled: :yaml)
+ return super unless use_traversal_ids_for_ancestors?
return self.class.none if parent_id.blank?
lineage(bottom: parent, hierarchy_order: hierarchy_order)
end
+ def ancestor_ids(hierarchy_order: nil)
+ return super unless use_traversal_ids_for_ancestors?
+
+ hierarchy_order == :desc ? traversal_ids[0..-2] : traversal_ids[0..-2].reverse
+ end
+
+ def self_and_ancestors(hierarchy_order: nil)
+ return super unless use_traversal_ids_for_ancestors?
+
+ return self.class.where(id: id) if parent_id.blank?
+
+ lineage(bottom: self, hierarchy_order: hierarchy_order)
+ end
+
+ def self_and_ancestor_ids(hierarchy_order: nil)
+ return super unless use_traversal_ids_for_ancestors?
+
+ hierarchy_order == :desc ? traversal_ids : traversal_ids.reverse
+ end
+
private
# Update the traversal_ids for the full hierarchy.