Commit 9e0da6ac authored by Corinna Wiesner's avatar Corinna Wiesner

Add recursive approach for Namespace#all_projects

Add a recursive approach to load all projects for a namespace next to
the existing route path wildcard approach. The new approach is guarded
by a feature flag.
parent 021ec839
...@@ -283,7 +283,11 @@ class Namespace < ApplicationRecord ...@@ -283,7 +283,11 @@ 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
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 end
# Includes pipelines from this namespace and pipelines from all subgroups # Includes pipelines from this namespace and pipelines from all subgroups
......
---
title: Add recursive approach to Namespace#all_projects
merge_request: 44740
author:
type: changed
---
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
...@@ -53,8 +53,21 @@ RSpec.describe UpdateBuildMinutesService do ...@@ -53,8 +53,21 @@ RSpec.describe UpdateBuildMinutesService do
it 'creates a statistics in root namespace' do it 'creates a statistics in root namespace' do
subject subject
expect(root_ancestor.namespace_statistics.reload.shared_runners_seconds) expect(root_ancestor.namespace_statistics&.shared_runners_seconds)
.to eq(build.duration.to_i * 2) .to be_nil
end
context 'with disabled feature flag :recursive_approach_for_all_projects in Namespace#all_projects' do
before do
stub_feature_flags(recursive_approach_for_all_projects: false)
end
it 'creates a statistics in root namespace' do
subject
expect(root_ancestor.namespace_statistics.reload.shared_runners_seconds)
.to eq(build.duration.to_i * 2)
end
end end
end end
......
...@@ -855,13 +855,31 @@ RSpec.describe Namespace do ...@@ -855,13 +855,31 @@ 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(:group) { create(:group) }
let!(:project1) { create(:project_empty_repo, namespace: group) } let(:child) { create(:group, parent: group) }
let!(:project2) { create(:project_empty_repo, namespace: child) } let!(:project1) { create(:project_empty_repo, namespace: group) }
let!(:project2) { create(:project_empty_repo, namespace: child) }
it { expect(group.all_projects.to_a).to match_array([project2, project1]) } 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(child.all_projects.to_a).to match_array([project2]) }
end
context 'with recursive approach' do
before do
stub_feature_flags(recursive_approach_for_all_projects: true)
end
include_examples 'all projects for a namespace'
end
context 'with route path wildcard approach' do
before do
stub_feature_flags(recursive_approach_for_all_projects: false)
end
include_examples 'all projects for a namespace'
end
end end
describe '#all_pipelines' do 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