Skip projects filter on issues search

When searching for issues, an additional subquery
is added which filters only issues in a project. If global context is
used (no project is specified) this query filters all projects user has
access to.

In that case we can skip this filter because filtering only projects
user has access to is added anyway.

The filter is used only if a custom project context is specified

Related to #40540
This commit is contained in:
Jan Provaznik 2017-12-22 16:44:53 +01:00
parent 05292ba958
commit 017c1297cd
3 changed files with 37 additions and 8 deletions

View file

@ -0,0 +1,5 @@
---
title: Improve search query for issues.
merge_request:
author:
type: performance

View file

@ -82,7 +82,10 @@ module Gitlab
end end
def issues def issues
issues = IssuesFinder.new(current_user).execute.where(project_id: project_ids_relation) issues = IssuesFinder.new(current_user).execute
unless default_project_filter
issues = issues.where(project_id: project_ids_relation)
end
issues = issues =
if query =~ /#(\d+)\z/ if query =~ /#(\d+)\z/

View file

@ -52,15 +52,36 @@ describe Gitlab::SearchResults do
expect(results.objects('merge_requests')).to include merge_request_2 expect(results.objects('merge_requests')).to include merge_request_2
end end
it 'includes project filter by default' do describe '#merge_requests' do
expect(results).to receive(:project_ids_relation).and_call_original it 'includes project filter by default' do
results.objects('merge_requests') expect(results).to receive(:project_ids_relation).and_call_original
results.objects('merge_requests')
end
it 'it skips project filter if default project context is used' do
allow(results).to receive(:default_project_filter).and_return(true)
expect(results).not_to receive(:project_ids_relation)
results.objects('merge_requests')
end
end end
it 'it skips project filter if default is used' do describe '#issues' do
allow(results).to receive(:default_project_filter).and_return(true) it 'includes project filter by default' do
expect(results).not_to receive(:project_ids_relation) expect(results).to receive(:project_ids_relation).and_call_original
results.objects('merge_requests')
results.objects('issues')
end
it 'it skips project filter if default project context is used' do
allow(results).to receive(:default_project_filter).and_return(true)
expect(results).not_to receive(:project_ids_relation)
results.objects('issues')
end
end end
end end