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
92661655
Commit
92661655
authored
Apr 30, 2021
by
Imre Farkas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid using contained by psql operator
parent
f0feebb5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
15 deletions
+11
-15
app/models/namespaces/traversal/linear.rb
app/models/namespaces/traversal/linear.rb
+1
-6
spec/models/group_spec.rb
spec/models/group_spec.rb
+1
-1
spec/support/shared_examples/namespaces/traversal_examples.rb
.../support/shared_examples/namespaces/traversal_examples.rb
+9
-8
No files found.
app/models/namespaces/traversal/linear.rb
View file @
92661655
...
...
@@ -45,7 +45,6 @@ module Namespaces
after_update
:sync_traversal_ids
,
if:
->
{
sync_traversal_ids?
&&
saved_change_to_parent_id?
}
scope
:traversal_ids_contains
,
->
(
ids
)
{
where
(
"traversal_ids @> (?)"
,
ids
)
}
scope
:traversal_ids_contained_by
,
->
(
ids
)
{
where
(
"traversal_ids <@ (?)"
,
ids
)
}
end
def
sync_traversal_ids?
...
...
@@ -102,7 +101,7 @@ module Namespaces
end
if
bottom
skope
=
skope
.
traversal_ids_contained_by
(
sql_array
(
bottom
.
traversal_ids
)
)
skope
=
skope
.
where
(
id:
bottom
.
traversal_ids
[
0
..-
1
]
)
end
# The original `with_depth` attribute in ObjectHierarchy increments as you
...
...
@@ -116,10 +115,6 @@ module Namespaces
skope
end
def
sql_array
(
ids
)
"{
#{
ids
.
join
(
','
)
}
}"
end
end
end
end
spec/models/group_spec.rb
View file @
92661655
...
...
@@ -454,7 +454,7 @@ RSpec.describe Group do
end
describe
'#ancestors'
do
it
{
expect
(
group
.
ancestors
.
to_sql
).
to
include
'traversal_ids <@'
}
it
{
expect
(
group
.
ancestors
.
to_sql
).
to
include
"
\"
namespaces
\"
.
\"
id
\"
=
#{
group
.
parent_id
}
"
}
it
'hierarchy order'
do
expect
(
group
.
ancestors
(
hierarchy_order: :asc
).
to_sql
).
to
include
'ORDER BY "depth" ASC'
...
...
spec/support/shared_examples/namespaces/traversal_examples.rb
View file @
92661655
...
...
@@ -39,16 +39,17 @@ RSpec.shared_examples 'namespace traversal' do
end
describe
'#ancestors'
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:nested_group
)
{
create
(
:group
,
parent:
group
)
}
let
(
:deep_nested_group
)
{
create
(
:group
,
parent:
nested_group
)
}
let
(
:very_deep_nested_group
)
{
create
(
:group
,
parent:
deep_nested_group
)
}
let
_it_be
(
:group
)
{
create
(
:group
)
}
let
_it_be
(
:nested_group
)
{
create
(
:group
,
parent:
group
)
}
let
_it_be
(
:deep_nested_group
)
{
create
(
:group
,
parent:
nested_group
)
}
let
_it_be
(
:very_deep_nested_group
)
{
create
(
:group
,
parent:
deep_nested_group
)
}
it
'returns the correct ancestors'
do
expect
(
very_deep_nested_group
.
ancestors
).
to
include
(
group
,
nested_group
,
deep_nested_group
)
expect
(
deep_nested_group
.
ancestors
).
to
include
(
group
,
nested_group
)
expect
(
nested_group
.
ancestors
).
to
include
(
group
)
expect
(
group
.
ancestors
).
to
eq
([])
# #reload is called to make sure traversal_ids are reloaded
expect
(
very_deep_nested_group
.
reload
.
ancestors
).
to
contain_exactly
(
group
,
nested_group
,
deep_nested_group
)
expect
(
deep_nested_group
.
reload
.
ancestors
).
to
contain_exactly
(
group
,
nested_group
)
expect
(
nested_group
.
reload
.
ancestors
).
to
contain_exactly
(
group
)
expect
(
group
.
reload
.
ancestors
).
to
eq
([])
end
describe
'#recursive_ancestors'
do
...
...
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