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
2651bbe8
Commit
2651bbe8
authored
Mar 09, 2021
by
Adam Hegyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move recursive namespace query to INNER JOIN
Move recursive namespace query to INNER JOIN
parent
7a19b738
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
5 deletions
+32
-5
app/models/namespace.rb
app/models/namespace.rb
+7
-2
config/feature_flags/development/recursive_namespace_lookup_as_inner_join.yml
.../development/recursive_namespace_lookup_as_inner_join.yml
+8
-0
spec/models/namespace_spec.rb
spec/models/namespace_spec.rb
+17
-3
No files found.
app/models/namespace.rb
View file @
2651bbe8
...
@@ -260,8 +260,13 @@ class Namespace < ApplicationRecord
...
@@ -260,8 +260,13 @@ class Namespace < ApplicationRecord
# Includes projects from this namespace and projects from all subgroups
# Includes projects from this namespace and projects from all subgroups
# that belongs to this namespace
# that belongs to this namespace
def
all_projects
def
all_projects
namespace
=
user?
?
self
:
self_and_descendants
return
Project
.
where
(
namespace:
self
)
if
user?
Project
.
where
(
namespace:
namespace
)
if
Feature
.
enabled?
(
:recursive_namespace_lookup_as_inner_join
,
self
)
Project
.
joins
(
"INNER JOIN (
#{
self_and_descendants
.
select
(
:id
).
to_sql
}
) namespaces ON namespaces.id=projects.namespace_id"
)
else
Project
.
where
(
namespace:
self_and_descendants
)
end
end
end
# Includes pipelines from this namespace and pipelines from all subgroups
# Includes pipelines from this namespace and pipelines from all subgroups
...
...
config/feature_flags/development/recursive_namespace_lookup_as_inner_join.yml
0 → 100644
View file @
2651bbe8
---
name
:
recursive_namespace_lookup_as_inner_join
introduced_by_url
:
rollout_issue_url
:
milestone
:
'
13.10'
type
:
development
group
:
group::optimize
default_enabled
:
false
spec/models/namespace_spec.rb
View file @
2651bbe8
...
@@ -897,10 +897,24 @@ RSpec.describe Namespace do
...
@@ -897,10 +897,24 @@ RSpec.describe Namespace do
it
{
expect
(
namespace
.
all_projects
.
to_a
).
to
match_array
([
project2
,
project1
])
}
it
{
expect
(
namespace
.
all_projects
.
to_a
).
to
match_array
([
project2
,
project1
])
}
it
{
expect
(
child
.
all_projects
.
to_a
).
to
match_array
([
project2
])
}
it
{
expect
(
child
.
all_projects
.
to_a
).
to
match_array
([
project2
])
}
it
'queries for the namespace and its descendants'
do
context
'when recursive_namespace_lookup_as_inner_join feature flag is on'
do
expect
(
Project
).
to
receive
(
:where
).
with
(
namespace:
[
namespace
,
child
])
before
do
stub_feature_flags
(
recursive_namespace_lookup_as_inner_join:
true
)
end
it
'queries for the namespace and its descendants'
do
expect
(
namespace
.
all_projects
).
to
match_array
([
project1
,
project2
])
end
end
namespace
.
all_projects
context
'when recursive_namespace_lookup_as_inner_join feature flag is off'
do
before
do
stub_feature_flags
(
recursive_namespace_lookup_as_inner_join:
false
)
end
it
'queries for the namespace and its descendants'
do
expect
(
namespace
.
all_projects
).
to
match_array
([
project1
,
project2
])
end
end
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