Commit f07bcc8c authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'refactor_namespace_all_projects' into 'master'

Add recursive approach for Namespace#all_projects

See merge request gitlab-org/gitlab!44740
parents 9e04302c 59672bed
...@@ -283,8 +283,12 @@ class Namespace < ApplicationRecord ...@@ -283,8 +283,12 @@ 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
if Feature.enabled?(:recursive_approach_for_all_projects)
Project.where(namespace: self_and_descendants)
else
Project.inside_path(full_path) Project.inside_path(full_path)
end end
end
# Includes pipelines from this namespace and pipelines from all subgroups # Includes pipelines from this namespace and pipelines from all subgroups
# that belongs to this namespace # that belongs to this namespace
......
---
name: recursive_approach_for_all_projects
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/44740
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/263442
type: development
group: group::fulfillment
default_enabled: false
...@@ -46,11 +46,11 @@ RSpec.describe UpdateBuildMinutesService do ...@@ -46,11 +46,11 @@ RSpec.describe UpdateBuildMinutesService do
end end
end end
context 'when namespace is subgroup' do context 'when group is subgroup' do
let(:root_ancestor) { create(:group, shared_runners_minutes_limit: 100) } let(:root_ancestor) { create(:group, shared_runners_minutes_limit: 100) }
let(:namespace) { create(:namespace, parent: root_ancestor) } let(:namespace) { create(:group, parent: root_ancestor) }
it 'creates a statistics in root namespace' do it 'creates a statistics in root group' do
subject subject
expect(root_ancestor.namespace_statistics.reload.shared_runners_seconds) expect(root_ancestor.namespace_statistics.reload.shared_runners_seconds)
......
...@@ -855,15 +855,51 @@ RSpec.describe Namespace do ...@@ -855,15 +855,51 @@ RSpec.describe Namespace do
end end
describe '#all_projects' do describe '#all_projects' do
let(:group) { create(:group) } shared_examples 'all projects for a namespace' do
let(:child) { create(:group, parent: group) } let(:namespace) { create(:namespace) }
let!(:project1) { create(:project_empty_repo, namespace: group) } let(:child) { create(:group, parent: namespace) }
let!(:project1) { create(:project_empty_repo, namespace: namespace) }
let!(:project2) { create(:project_empty_repo, namespace: child) } let!(:project2) { create(:project_empty_repo, namespace: child) }
it { expect(group.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]) }
end end
shared_examples 'all project examples' do
include_examples 'all projects for a namespace'
context 'when namespace is a group' do
let_it_be(:namespace) { create(:group) }
include_examples 'all projects for a namespace'
end
context 'when namespace is a user namespace' do
let_it_be(:user) { create(:user) }
let_it_be(:user_namespace) { create(:namespace, owner: user) }
let_it_be(:project) { create(:project, namespace: user_namespace) }
it { expect(user_namespace.all_projects.to_a).to match_array([project]) }
end
end
context 'with recursive approach' do
before do
stub_feature_flags(recursive_approach_for_all_projects: true)
end
include_examples 'all project examples'
end
context 'with route path wildcard approach' do
before do
stub_feature_flags(recursive_approach_for_all_projects: false)
end
include_examples 'all project examples'
end
end
describe '#all_pipelines' do describe '#all_pipelines' do
let(:group) { create(:group) } let(:group) { create(:group) }
let(:child) { create(:group, parent: group) } let(:child) { create(:group, parent: group) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment