Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
9ab346f1
Commit
9ab346f1
authored
Nov 11, 2021
by
Alex Pooley
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Query scope for group ancestor roots
Includes a recursive and linear version toggled by a feature flag.
parent
80f681f7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
74 additions
and
0 deletions
+74
-0
app/models/namespaces/traversal/linear_scopes.rb
app/models/namespaces/traversal/linear_scopes.rb
+12
-0
app/models/namespaces/traversal/recursive_scopes.rb
app/models/namespaces/traversal/recursive_scopes.rb
+7
-0
config/feature_flags/development/use_traversal_ids_roots.yml
config/feature_flags/development/use_traversal_ids_roots.yml
+8
-0
spec/support/shared_examples/namespaces/traversal_scope_examples.rb
...rt/shared_examples/namespaces/traversal_scope_examples.rb
+47
-0
No files found.
app/models/namespaces/traversal/linear_scopes.rb
View file @
9ab346f1
...
...
@@ -15,6 +15,13 @@ module Namespaces
select
(
'namespaces.traversal_ids[array_length(namespaces.traversal_ids, 1)] AS id'
)
end
def
roots
return
super
unless
use_traversal_ids_roots?
root_ids
=
all
.
select
(
"
#{
quoted_table_name
}
.traversal_ids[1]"
).
distinct
unscoped
.
where
(
id:
root_ids
)
end
def
self_and_ancestors
(
include_self:
true
,
hierarchy_order:
nil
)
return
super
unless
use_traversal_ids_for_ancestor_scopes?
...
...
@@ -83,6 +90,11 @@ module Namespaces
Feature
.
enabled?
(
:use_traversal_ids
,
default_enabled: :yaml
)
end
def
use_traversal_ids_roots?
Feature
.
enabled?
(
:use_traversal_ids_roots
,
default_enabled: :yaml
)
&&
use_traversal_ids?
end
def
use_traversal_ids_for_ancestor_scopes?
Feature
.
enabled?
(
:use_traversal_ids_for_ancestor_scopes
,
default_enabled: :yaml
)
&&
use_traversal_ids?
...
...
app/models/namespaces/traversal/recursive_scopes.rb
View file @
9ab346f1
...
...
@@ -10,6 +10,13 @@ module Namespaces
select
(
'id'
)
end
def
roots
Gitlab
::
ObjectHierarchy
.
new
(
all
)
.
base_and_ancestors
.
where
(
namespaces:
{
parent_id:
nil
})
end
def
self_and_ancestors
(
include_self:
true
,
hierarchy_order:
nil
)
records
=
Gitlab
::
ObjectHierarchy
.
new
(
all
).
base_and_ancestors
(
hierarchy_order:
hierarchy_order
)
...
...
config/feature_flags/development/use_traversal_ids_roots.yml
0 → 100644
View file @
9ab346f1
---
name
:
use_traversal_ids_roots
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/74148
rollout_issue_url
:
https://gitlab.com/gitlab-org/gitlab/-/issues/345438
milestone
:
'
14.5'
type
:
development
group
:
group::workspace
default_enabled
:
false
spec/support/shared_examples/namespaces/traversal_scope_examples.rb
View file @
9ab346f1
...
...
@@ -49,6 +49,53 @@ RSpec.shared_examples 'namespace traversal scopes' do
it
{
is_expected
.
to
eq
described_class
.
column_names
}
end
shared_examples
'.roots'
do
context
'with only sub-groups'
do
subject
{
described_class
.
where
(
id:
[
deep_nested_group_1
,
nested_group_1
,
deep_nested_group_2
]).
roots
}
it
{
is_expected
.
to
contain_exactly
(
group_1
,
group_2
)
}
end
context
'with only root groups'
do
subject
{
described_class
.
where
(
id:
[
group_1
,
group_2
]).
roots
}
it
{
is_expected
.
to
contain_exactly
(
group_1
,
group_2
)
}
end
context
'with all groups'
do
subject
{
described_class
.
where
(
id:
groups
).
roots
}
it
{
is_expected
.
to
contain_exactly
(
group_1
,
group_2
)
}
end
end
describe
'.roots'
do
context
"use_traversal_ids_roots feature flag is true"
do
before
do
stub_feature_flags
(
use_traversal_ids:
true
)
stub_feature_flags
(
use_traversal_ids_roots:
true
)
end
it_behaves_like
'.roots'
it
'not make recursive queries'
do
expect
{
described_class
.
where
(
id:
[
nested_group_1
]).
roots
.
load
}.
not_to
make_queries_matching
(
/WITH RECURSIVE/
)
end
end
context
"use_traversal_ids_roots feature flag is false"
do
before
do
stub_feature_flags
(
use_traversal_ids_roots:
false
)
end
it_behaves_like
'.roots'
it
'make recursive queries'
do
expect
{
described_class
.
where
(
id:
[
nested_group_1
]).
roots
.
load
}.
to
make_queries_matching
(
/WITH RECURSIVE/
)
end
end
end
shared_examples
'.self_and_ancestors'
do
subject
{
described_class
.
where
(
id:
[
nested_group_1
,
nested_group_2
]).
self_and_ancestors
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment