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
b9f38e32
Commit
b9f38e32
authored
Apr 12, 2021
by
Alex Pooley
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Direct access to recursive traversal methods
parent
f028aff4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
1 deletion
+52
-1
app/models/namespaces/traversal/recursive.rb
app/models/namespaces/traversal/recursive.rb
+5
-0
ee/app/finders/epics_finder.rb
ee/app/finders/epics_finder.rb
+1
-1
spec/support/shared_examples/namespaces/namespace_traversal_examples.rb
...hared_examples/namespaces/namespace_traversal_examples.rb
+46
-0
No files found.
app/models/namespaces/traversal/recursive.rb
View file @
b9f38e32
...
...
@@ -22,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
...
...
@@ -30,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
...
...
@@ -44,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
)
})
...
...
ee/app/finders/epics_finder.rb
View file @
b9f38e32
...
...
@@ -162,7 +162,7 @@ class EpicsFinder < IssuableFinder
elsif
include_ancestors
group
.
self_and_ancestors
elsif
include_descendants
group
.
self_and_descendants
group
.
recursive_
self_and_descendants
else
Group
.
id_in
(
group
.
id
)
end
...
...
spec/support/shared_examples/namespaces/namespace_traversal_examples.rb
View file @
b9f38e32
# frozen_string_literal: true
RSpec
.
shared_examples
'namespace traversal'
do
shared_examples
'recursive version'
do
|
method
|
let
(
:recursive_method
)
{
"recursive_
#{
method
}
"
}
it
"is equivalent to #
#{
method
}
"
do
groups
.
each
do
|
group
|
expect
(
group
.
public_send
(
method
)).
to
match_array
group
.
public_send
(
recursive_method
)
end
end
it
"makes a recursive query"
do
groups
.
each
do
|
group
|
expect
{
group
.
public_send
(
recursive_method
).
load
}.
to
make_queries_matching
(
/WITH RECURSIVE/
)
end
end
end
describe
'#self_and_hierarchy'
do
let!
(
:group
)
{
create
(
:group
,
path:
'git_lab'
)
}
let!
(
:nested_group
)
{
create
(
:group
,
parent:
group
)
}
...
...
@@ -14,6 +30,12 @@ RSpec.shared_examples 'namespace traversal' do
expect
(
nested_group
.
self_and_hierarchy
).
to
contain_exactly
(
group
,
nested_group
,
deep_nested_group
,
very_deep_nested_group
)
expect
(
very_deep_nested_group
.
self_and_hierarchy
).
to
contain_exactly
(
group
,
nested_group
,
deep_nested_group
,
very_deep_nested_group
)
end
describe
'#recursive_self_and_hierarchy'
do
let
(
:groups
)
{
[
group
,
nested_group
,
very_deep_nested_group
]
}
it_behaves_like
'recursive version'
,
:self_and_hierarchy
end
end
describe
'#ancestors'
do
...
...
@@ -28,6 +50,12 @@ RSpec.shared_examples 'namespace traversal' do
expect
(
nested_group
.
ancestors
).
to
include
(
group
)
expect
(
group
.
ancestors
).
to
eq
([])
end
describe
'#recursive_ancestors'
do
let
(
:groups
)
{
[
nested_group
,
deep_nested_group
,
very_deep_nested_group
]
}
it_behaves_like
'recursive version'
,
:ancestors
end
end
describe
'#self_and_ancestors'
do
...
...
@@ -42,6 +70,12 @@ RSpec.shared_examples 'namespace traversal' do
expect
(
nested_group
.
self_and_ancestors
).
to
contain_exactly
(
group
,
nested_group
)
expect
(
group
.
self_and_ancestors
).
to
contain_exactly
(
group
)
end
describe
'#recursive_self_and_ancestors'
do
let
(
:groups
)
{
[
nested_group
,
deep_nested_group
,
very_deep_nested_group
]
}
it_behaves_like
'recursive version'
,
:self_and_ancestors
end
end
describe
'#descendants'
do
...
...
@@ -58,6 +92,12 @@ RSpec.shared_examples 'namespace traversal' do
expect
(
nested_group
.
descendants
.
to_a
).
to
include
(
deep_nested_group
,
very_deep_nested_group
)
expect
(
group
.
descendants
.
to_a
).
to
include
(
nested_group
,
deep_nested_group
,
very_deep_nested_group
)
end
describe
'#recursive_descendants'
do
let
(
:groups
)
{
[
group
,
nested_group
,
deep_nested_group
,
very_deep_nested_group
]
}
it_behaves_like
'recursive version'
,
:descendants
end
end
describe
'#self_and_descendants'
do
...
...
@@ -74,5 +114,11 @@ RSpec.shared_examples 'namespace traversal' do
expect
(
nested_group
.
self_and_descendants
).
to
contain_exactly
(
nested_group
,
deep_nested_group
,
very_deep_nested_group
)
expect
(
group
.
self_and_descendants
).
to
contain_exactly
(
group
,
nested_group
,
deep_nested_group
,
very_deep_nested_group
)
end
describe
'#recursive_self_and_descendants'
do
let
(
:groups
)
{
[
group
,
nested_group
,
deep_nested_group
,
very_deep_nested_group
]
}
it_behaves_like
'recursive version'
,
:self_and_descendants
end
end
end
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