Commit 6d35c88b authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '335064-slow-namespace-all_projects' into 'master'

Resolve "Slow Namespace#all_projects"

See merge request gitlab-org/gitlab!65296
parents ee816a4c e0cc0fc6
...@@ -280,7 +280,7 @@ class Namespace < ApplicationRecord ...@@ -280,7 +280,7 @@ class Namespace < ApplicationRecord
# that belongs to this namespace # that belongs to this namespace
def all_projects def all_projects
if Feature.enabled?(:recursive_approach_for_all_projects, default_enabled: :yaml) 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) Project.where(namespace: namespace)
else else
Project.inside_path(full_path) Project.inside_path(full_path)
......
...@@ -1097,6 +1097,14 @@ RSpec.describe Namespace do ...@@ -1097,6 +1097,14 @@ RSpec.describe Namespace do
end end
include_examples '#all_projects' 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 end
context 'with use_traversal_ids feature flag disabled' do 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