Commit e0cc0fc6 authored by Alex Pooley's avatar Alex Pooley

Fix Namespace#all_projects performance

Changelog: performance
parent 9dce5fff
......@@ -280,7 +280,7 @@ class Namespace < ApplicationRecord
# that belongs to this namespace
def all_projects
if Feature.enabled?(:recursive_approach_for_all_projects, default_enabled: :yaml)
namespace = user? ? self : self_and_descendants
namespace = user? ? self : self_and_descendant_ids
Project.where(namespace: namespace)
else
Project.inside_path(full_path)
......
......@@ -1097,6 +1097,14 @@ RSpec.describe Namespace do
end
include_examples '#all_projects'
# Using #self_and_descendant instead of #self_and_descendant_ids can produce
# very slow queries.
it 'calls self_and_descendant_ids' do
namespace = create(:group)
expect(namespace).to receive(:self_and_descendant_ids)
namespace.all_projects
end
end
context 'with use_traversal_ids feature flag disabled' 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