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_scopes.rb')
-rw-r--r--app/models/namespaces/traversal/linear_scopes.rb61
1 files changed, 7 insertions, 54 deletions
diff --git a/app/models/namespaces/traversal/linear_scopes.rb b/app/models/namespaces/traversal/linear_scopes.rb
index 6f404ec12d0..81ac026d7ff 100644
--- a/app/models/namespaces/traversal/linear_scopes.rb
+++ b/app/models/namespaces/traversal/linear_scopes.rb
@@ -27,15 +27,9 @@ module Namespaces
def self_and_ancestors(include_self: true, upto: nil, hierarchy_order: nil)
return super unless use_traversal_ids_for_ancestor_scopes?
- if Feature.enabled?(:use_traversal_ids_for_ancestor_scopes_with_inner_join)
- self_and_ancestors_from_inner_join(include_self: include_self,
- upto: upto, hierarchy_order:
- hierarchy_order)
- else
- self_and_ancestors_from_ancestors_cte(include_self: include_self,
- upto: upto,
- hierarchy_order: hierarchy_order)
- end
+ self_and_ancestors_from_inner_join(include_self: include_self,
+ upto: upto, hierarchy_order:
+ hierarchy_order)
end
def self_and_ancestor_ids(include_self: true)
@@ -117,37 +111,6 @@ module Namespaces
use_traversal_ids?
end
- def self_and_ancestors_from_ancestors_cte(include_self: true, upto: nil, hierarchy_order: nil)
- base_cte = all.select('namespaces.id', 'namespaces.traversal_ids').as_cte(:base_ancestors_cte)
-
- # We have to alias id with 'AS' to avoid ambiguous column references by calling methods.
- ancestors_cte = unscoped
- .unscope(where: [:type])
- .select('id as base_id',
- "#{unnest_func(base_cte.table['traversal_ids']).to_sql} as ancestor_id")
- .from(base_cte.table)
- .as_cte(:ancestors_cte)
-
- namespaces = Arel::Table.new(:namespaces)
-
- records = unscoped
- .with(base_cte.to_arel, ancestors_cte.to_arel)
- .distinct
- .from([ancestors_cte.table, namespaces])
- .where(namespaces[:id].eq(ancestors_cte.table[:ancestor_id]))
- .order_by_depth(hierarchy_order)
-
- unless include_self
- records = records.where(ancestors_cte.table[:base_id].not_eq(ancestors_cte.table[:ancestor_id]))
- end
-
- if upto
- records = records.where.not(id: unscoped.where(id: upto).select('unnest(traversal_ids)'))
- end
-
- records
- end
-
def self_and_ancestors_from_inner_join(include_self: true, upto: nil, hierarchy_order: nil)
base_cte = all.reselect('namespaces.traversal_ids').as_cte(:base_ancestors_cte)
@@ -181,25 +144,15 @@ module Namespaces
end
def self_and_descendants_with_comparison_operators(include_self: true)
- base = all.select(:traversal_ids)
- base = base.select(:id) if Feature.enabled?(:linear_scopes_superset)
+ base = all.select(:id, :traversal_ids)
base_cte = base.as_cte(:descendants_base_cte)
namespaces = Arel::Table.new(:namespaces)
- withs = [base_cte.to_arel]
- froms = []
-
- if Feature.enabled?(:linear_scopes_superset)
- superset_cte = self.superset_cte(base_cte.table.name)
- withs += [superset_cte.to_arel]
- froms = [superset_cte.table]
- else
- froms = [base_cte.table]
- end
-
+ superset_cte = self.superset_cte(base_cte.table.name)
+ withs = [base_cte.to_arel, superset_cte.to_arel]
# Order is important. namespace should be last to handle future joins.
- froms += [namespaces]
+ froms = [superset_cte.table, namespaces]
base_ref = froms.first