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
0b1bd654
Commit
0b1bd654
authored
Jul 05, 2021
by
Alex Pooley
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use linear root_ancestor when possible
Changelog: performance
parent
3786e987
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
6 deletions
+48
-6
app/models/namespaces/traversal/linear.rb
app/models/namespaces/traversal/linear.rb
+12
-6
spec/models/namespace_spec.rb
spec/models/namespace_spec.rb
+36
-0
No files found.
app/models/namespaces/traversal/linear.rb
View file @
0b1bd654
...
...
@@ -71,15 +71,21 @@ module Namespaces
traversal_ids
.
present?
end
def
root_ancestor
return
super
if
parent
.
nil?
return
super
unless
persisted?
def
use_traversal_ids_for_root_ancestor?
return
false
unless
Feature
.
enabled?
(
:use_traversal_ids_for_root_ancestor
,
default_enabled: :yaml
)
return
super
if
traversal_ids
.
blank?
return
super
unless
Feature
.
enabled?
(
:use_traversal_ids_for_root_ancestor
,
default_enabled: :yaml
)
traversal_ids
.
present?
end
def
root_ancestor
return
super
unless
use_traversal_ids_for_root_ancestor?
strong_memoize
(
:root_ancestor
)
do
Namespace
.
find_by
(
id:
traversal_ids
.
first
)
if
parent
.
nil?
self
else
Namespace
.
find_by
(
id:
traversal_ids
.
first
)
end
end
end
...
...
spec/models/namespace_spec.rb
View file @
0b1bd654
...
...
@@ -974,6 +974,14 @@ RSpec.describe Namespace do
end
end
shared_examples
'disabled feature flag when traversal_ids is blank'
do
before
do
namespace
.
traversal_ids
=
[]
end
it
{
is_expected
.
to
eq
false
}
end
describe
'#use_traversal_ids?'
do
let_it_be
(
:namespace
,
reload:
true
)
{
create
(
:namespace
)
}
...
...
@@ -985,6 +993,8 @@ RSpec.describe Namespace do
end
it
{
is_expected
.
to
eq
true
}
it_behaves_like
'disabled feature flag when traversal_ids is blank'
end
context
'when use_traversal_ids feature flag is false'
do
...
...
@@ -996,6 +1006,30 @@ RSpec.describe Namespace do
end
end
describe
'#use_traversal_ids_for_root_ancestor?'
do
let_it_be
(
:namespace
,
reload:
true
)
{
create
(
:namespace
)
}
subject
{
namespace
.
use_traversal_ids_for_root_ancestor?
}
context
'when use_traversal_ids_for_root_ancestor feature flag is true'
do
before
do
stub_feature_flags
(
use_traversal_ids_for_root_ancestor:
true
)
end
it
{
is_expected
.
to
eq
true
}
it_behaves_like
'disabled feature flag when traversal_ids is blank'
end
context
'when use_traversal_ids_for_root_ancestor feature flag is false'
do
before
do
stub_feature_flags
(
use_traversal_ids_for_root_ancestor:
false
)
end
it
{
is_expected
.
to
eq
false
}
end
end
describe
'#use_traversal_ids_for_ancestors?'
do
let_it_be
(
:namespace
,
reload:
true
)
{
create
(
:namespace
)
}
...
...
@@ -1007,6 +1041,8 @@ RSpec.describe Namespace do
end
it
{
is_expected
.
to
eq
true
}
it_behaves_like
'disabled feature flag when traversal_ids is blank'
end
context
'when use_traversal_ids_for_ancestors? feature flag is false'
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