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')
-rw-r--r--app/models/namespaces/traversal/linear.rb10
-rw-r--r--app/models/namespaces/traversal/linear_scopes.rb29
2 files changed, 9 insertions, 30 deletions
diff --git a/app/models/namespaces/traversal/linear.rb b/app/models/namespaces/traversal/linear.rb
index 687fa6a5334..16a9c20dfdc 100644
--- a/app/models/namespaces/traversal/linear.rb
+++ b/app/models/namespaces/traversal/linear.rb
@@ -47,6 +47,8 @@ module Namespaces
# This uses rails internal before_commit API to sync traversal_ids on namespace create, right before transaction is committed.
# This helps reduce the time during which the root namespace record is locked to ensure updated traversal_ids are valid
before_commit :sync_traversal_ids, on: [:create]
+
+ define_model_callbacks :sync_traversal_ids
end
class_methods do
@@ -208,10 +210,12 @@ module Namespaces
#
# NOTE: self.traversal_ids will be stale. Reload for a fresh record.
def sync_traversal_ids
- # Clear any previously memoized root_ancestor as our ancestors have changed.
- clear_memoization(:root_ancestor)
+ run_callbacks :sync_traversal_ids do
+ # Clear any previously memoized root_ancestor as our ancestors have changed.
+ clear_memoization(:root_ancestor)
- Namespace::TraversalHierarchy.for_namespace(self).sync_traversal_ids!
+ Namespace::TraversalHierarchy.for_namespace(self).sync_traversal_ids!
+ end
end
# Lock the root of the hierarchy we just left, and lock the root of the hierarchy
diff --git a/app/models/namespaces/traversal/linear_scopes.rb b/app/models/namespaces/traversal/linear_scopes.rb
index 81ac026d7ff..843de9bce33 100644
--- a/app/models/namespaces/traversal/linear_scopes.rb
+++ b/app/models/namespaces/traversal/linear_scopes.rb
@@ -41,24 +41,13 @@ module Namespaces
def self_and_descendants(include_self: true)
return super unless use_traversal_ids_for_descendants_scopes?
- if Feature.enabled?(:traversal_ids_btree)
- self_and_descendants_with_comparison_operators(include_self: include_self)
- else
- records = self_and_descendants_with_duplicates_with_array_operator(include_self: include_self)
- distinct = records.select('DISTINCT on(namespaces.id) namespaces.*')
- distinct.normal_select
- end
+ self_and_descendants_with_comparison_operators(include_self: include_self)
end
def self_and_descendant_ids(include_self: true)
return super unless use_traversal_ids_for_descendants_scopes?
- if Feature.enabled?(:traversal_ids_btree)
- self_and_descendants_with_comparison_operators(include_self: include_self).as_ids
- else
- self_and_descendants_with_duplicates_with_array_operator(include_self: include_self)
- .select('DISTINCT namespaces.id')
- end
+ self_and_descendants(include_self: include_self).as_ids
end
def self_and_hierarchy
@@ -181,20 +170,6 @@ module Namespaces
Arel::Nodes::NamedFunction.new('unnest', args)
end
- def self_and_descendants_with_duplicates_with_array_operator(include_self: true)
- base_ids = select(:id)
-
- records = unscoped
- .from("namespaces, (#{base_ids.to_sql}) base")
- .where('namespaces.traversal_ids @> ARRAY[base.id]')
-
- if include_self
- records
- else
- records.where('namespaces.id <> base.id')
- end
- end
-
def superset_cte(base_name)
superset_sql = <<~SQL
SELECT d1.traversal_ids