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 ...@@ -31,8 +31,12 @@ class ForkNamespaceEntity < Grape::Entity
end end
expose :can_create_project do |namespace, options| 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) options[:current_user].can?(:create_projects, namespace)
end end
end
private private
......
...@@ -211,11 +211,7 @@ RSpec.describe Projects::ForksController do ...@@ -211,11 +211,7 @@ RSpec.describe Projects::ForksController do
create(:group, :public).add_owner(user) create(:group, :public).add_owner(user)
# TODO: There is another N+1 caused by user.can?(:create_projects, namespace) expect { do_request.call }.not_to exceed_query_limit(control)
# Defined in ForkNamespaceEntity
extra_count = 1
expect { do_request.call }.not_to exceed_query_limit(control.count + extra_count)
end end
end end
end end
......
...@@ -60,6 +60,15 @@ RSpec.describe ForkNamespaceEntity do ...@@ -60,6 +60,15 @@ RSpec.describe ForkNamespaceEntity do
expect(json[:permission]).to eql 'Developer' expect(json[:permission]).to eql 'Developer'
end 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 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) allow(user).to receive(:can?).with(:create_projects, namespace).and_return(true)
...@@ -71,4 +80,5 @@ RSpec.describe ForkNamespaceEntity do ...@@ -71,4 +80,5 @@ RSpec.describe ForkNamespaceEntity do
expect(json[:can_create_project]).to be false expect(json[:can_create_project]).to be false
end end
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