Skip to content
Snippets Groups Projects
Unverified Commit 46174ff5 authored by Joe Woodward's avatar Joe Woodward Committed by GitLab
Browse files

Merge branch '482942_optimize_group_call' into 'master'

Optimization: don't load group if not needed

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/169276



Merged-by: default avatarJoe Woodward <jwoodward@gitlab.com>
Approved-by: default avatarOlaoluwa Oluro <olaoluro@gitlab.com>
Approved-by: default avatarJoe Woodward <jwoodward@gitlab.com>
Co-authored-by: default avatarVasilii Iakliushin <viakliushin@gitlab.com>
parents b6b134ac 9e5ad5aa
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -7,7 +7,7 @@ class ProtectedBranch < ApplicationRecord
include EachBatch
include Presentable
 
belongs_to :group, foreign_key: :namespace_id, touch: true, inverse_of: :protected_branches
belongs_to :group, foreign_key: :namespace_id, touch: true, inverse_of: :protected_branches, optional: true
 
validate :validate_either_project_or_top_group
validates :name, uniqueness: { scope: [:project_id, :namespace_id] }, if: :name_changed?
Loading
Loading
Loading
Loading
@@ -307,6 +307,44 @@
end
end
 
describe '#supports_unprotection_restrictions?' do
subject(:supports_unprotection_restrictions) { protected_branch.supports_unprotection_restrictions? }
context 'when the `namespace_id` is nil' do
before do
protected_branch.assign_attributes(namespace_id: nil)
end
context 'when feature is not licensed' do
before do
stub_licensed_features(unprotection_restrictions: false)
end
it { is_expected.to be_falsey }
it 'does not load group without a reason' do
expect { subject }.not_to exceed_query_limit(0)
end
end
context 'when feature is licensed' do
before do
stub_licensed_features(unprotection_restrictions: true)
end
it { is_expected.to be_truthy }
end
end
context 'when the `namespace_id` is present' do
before do
protected_branch.assign_attributes(namespace_id: 123)
end
it { is_expected.to be_falsey }
end
end
describe '#allow_force_push' do
context 'when is not protected from push by security policy' do
context 'when the `allow_force_push` is true' do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment