Commit 945abee1 authored by Vasilii Iakliushin's avatar Vasilii Iakliushin

Fix N+1 problem for fork controller

Contributes to https://gitlab.com/gitlab-org/gitlab/-/issues/329751

Temporary removes code responsible for N+1 query.

The new frontend code does not use the result from
`can_create_project` field

Changelog: performance
parent fd7b3032
......@@ -31,8 +31,12 @@ class ForkNamespaceEntity < Grape::Entity
end
expose :can_create_project do |namespace, options|
if Feature.enabled?(:fork_project_form, options[:project], default_enabled: :yaml)
true
else
options[:current_user].can?(:create_projects, namespace)
end
end
private
......
......@@ -211,11 +211,7 @@ RSpec.describe Projects::ForksController do
create(:group, :public).add_owner(user)
# TODO: There is another N+1 caused by user.can?(:create_projects, namespace)
# Defined in ForkNamespaceEntity
extra_count = 1
expect { do_request.call }.not_to exceed_query_limit(control.count + extra_count)
expect { do_request.call }.not_to exceed_query_limit(control)
end
end
end
......
......@@ -60,6 +60,15 @@ RSpec.describe ForkNamespaceEntity do
expect(json[:permission]).to eql 'Developer'
end
it 'exposes can_create_project' do
expect(json[:can_create_project]).to be true
end
context 'when fork_project_form feature flag is disabled' do
before do
stub_feature_flags(fork_project_form: false)
end
it 'sets can_create_project to true when user can create projects in namespace' do
allow(user).to receive(:can?).with(:create_projects, namespace).and_return(true)
......@@ -71,4 +80,5 @@ RSpec.describe ForkNamespaceEntity do
expect(json[:can_create_project]).to be false
end
end
end
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