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,7 +283,11 @@ class Namespace < ApplicationRecord
# Includes projects from this namespace and projects from all subgroups
# that belongs to this namespace
def all_projects
Project.inside_path(full_path)
if Feature.enabled?(:recursive_approach_for_all_projects)
Project.where(namespace: self_and_descendants)
else
Project.inside_path(full_path)
end
end
# Includes pipelines from this namespace and pipelines from all subgroups
......
---
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
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(: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
expect(root_ancestor.namespace_statistics.reload.shared_runners_seconds)
......
......@@ -855,13 +855,49 @@ RSpec.describe Namespace do
end
describe '#all_projects' do
let(:group) { create(:group) }
let(:child) { create(:group, parent: group) }
let!(:project1) { create(:project_empty_repo, namespace: group) }
let!(:project2) { create(:project_empty_repo, namespace: child) }
shared_examples 'all projects for a namespace' do
let(:namespace) { create(:namespace) }
let(:child) { create(:group, parent: namespace) }
let!(:project1) { create(:project_empty_repo, namespace: namespace) }
let!(:project2) { create(:project_empty_repo, namespace: child) }
it { expect(namespace.all_projects.to_a).to match_array([project2, project1]) }
it { expect(child.all_projects.to_a).to match_array([project2]) }
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(group.all_projects.to_a).to match_array([project2, project1]) }
it { expect(child.all_projects.to_a).to match_array([project2]) }
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
......
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