diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 18:42:06 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 18:42:06 +0000 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/services/search_service_spec.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) | |
download | gitlab-ce-6e4e1050d9dba2b7b2523fdd1768823ab85feef4.tar.gz |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/services/search_service_spec.rb')
-rw-r--r-- | spec/services/search_service_spec.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/spec/services/search_service_spec.rb b/spec/services/search_service_spec.rb index 52aef73ac77..f6bb7acee57 100644 --- a/spec/services/search_service_spec.rb +++ b/spec/services/search_service_spec.rb @@ -374,6 +374,19 @@ RSpec.describe SearchService do subject(:result) { search_service.search_objects } + shared_examples "redaction limits N+1 queries" do |limit:| + it 'does not exceed the query limit' do + # issuing the query to remove the data loading call + unredacted_results.to_a + + # only the calls from the redaction are left + query = ActiveRecord::QueryRecorder.new { result } + + # these are the project authorization calls, which are not preloaded + expect(query.count).to be <= limit + end + end + def found_blob(project) Gitlab::Search::FoundBlob.new(project: project) end @@ -427,6 +440,12 @@ RSpec.describe SearchService do it 'redacts the inaccessible merge request' do expect(result).to contain_exactly(readable) end + + context 'with :with_api_entity_associations' do + let(:unredacted_results) { ar_relation(MergeRequest.with_api_entity_associations, readable, unreadable) } + + it_behaves_like "redaction limits N+1 queries", limit: 7 + end end context 'project repository blobs' do @@ -460,6 +479,10 @@ RSpec.describe SearchService do it 'redacts the inaccessible snippet' do expect(result).to contain_exactly(readable) end + + context 'with :with_api_entity_associations' do + it_behaves_like "redaction limits N+1 queries", limit: 12 + end end context 'personal snippets' do @@ -471,6 +494,10 @@ RSpec.describe SearchService do it 'redacts the inaccessible snippet' do expect(result).to contain_exactly(readable) end + + context 'with :with_api_entity_associations' do + it_behaves_like "redaction limits N+1 queries", limit: 3 + end end context 'commits' do |