Commit ad9e7c76 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'remove-duplicate-sql-query' into 'master'

Remove a second sql query for already loaded project in search#show

See merge request gitlab-org/gitlab!27282
parents 3f3c3057 860d2c73
...@@ -13,7 +13,7 @@ module EE ...@@ -13,7 +13,7 @@ module EE
::Gitlab::Elastic::ProjectSearchResults.new( ::Gitlab::Elastic::ProjectSearchResults.new(
current_user, current_user,
params[:search], params[:search],
project.id, project,
repository_ref repository_ref
) )
end end
......
...@@ -11,9 +11,9 @@ module Gitlab ...@@ -11,9 +11,9 @@ module Gitlab
delegate :users, to: :generic_search_results delegate :users, to: :generic_search_results
delegate :limited_users_count, to: :generic_search_results delegate :limited_users_count, to: :generic_search_results
def initialize(current_user, query, project_id, repository_ref = nil) def initialize(current_user, query, project, repository_ref = nil)
@current_user = current_user @current_user = current_user
@project = Project.find(project_id) @project = project
@repository_ref = repository_ref.presence || project.default_branch @repository_ref = repository_ref.presence || project.default_branch
@query = query @query = query
@public_and_internal_projects = false @public_and_internal_projects = false
......
...@@ -12,7 +12,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do ...@@ -12,7 +12,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do
end end
describe 'initialize with empty ref' do describe 'initialize with empty ref' do
subject(:results) { described_class.new(user, query, project.id, '') } subject(:results) { described_class.new(user, query, project, '') }
it { expect(results.project).to eq(project) } it { expect(results.project).to eq(project) }
it { expect(results.repository_ref).to eq('master') } it { expect(results.repository_ref).to eq('master') }
...@@ -22,7 +22,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do ...@@ -22,7 +22,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do
describe 'initialize with ref' do describe 'initialize with ref' do
let(:ref) { 'refs/heads/test' } let(:ref) { 'refs/heads/test' }
subject(:results) { described_class.new(user, query, project.id, ref) } subject(:results) { described_class.new(user, query, project, ref) }
it { expect(results.project).to eq(project) } it { expect(results.project).to eq(project) }
it { expect(results.repository_ref).to eq(ref) } it { expect(results.repository_ref).to eq(ref) }
...@@ -49,12 +49,12 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do ...@@ -49,12 +49,12 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do
ensure_elasticsearch_index! ensure_elasticsearch_index!
result = described_class.new(user, 'term', project.id) result = described_class.new(user, 'term', project)
expect(result.notes_count).to eq(1) expect(result.notes_count).to eq(1)
expect(result.wiki_blobs_count).to eq(1) expect(result.wiki_blobs_count).to eq(1)
expect(result.blobs_count).to eq(1) expect(result.blobs_count).to eq(1)
result1 = described_class.new(user, 'initial', project.id) result1 = described_class.new(user, 'initial', project)
expect(result1.commits_count).to eq(1) expect(result1.commits_count).to eq(1)
end end
...@@ -70,7 +70,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do ...@@ -70,7 +70,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do
ensure_elasticsearch_index! ensure_elasticsearch_index!
result = described_class.new(guest, 'term', project.id) result = described_class.new(guest, 'term', project)
expect(result.wiki_blobs_count).to eq(1) expect(result.wiki_blobs_count).to eq(1)
end end
end end
...@@ -79,7 +79,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do ...@@ -79,7 +79,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do
describe "search for commits in non-default branch" do describe "search for commits in non-default branch" do
let(:project) { create(:project, :public, :repository, visibility) } let(:project) { create(:project, :public, :repository, visibility) }
let(:visibility) { :repository_enabled } let(:visibility) { :repository_enabled }
let(:result) { described_class.new(user, 'initial', project.id, 'test') } let(:result) { described_class.new(user, 'initial', project, 'test') }
subject(:commits) { result.objects('commits') } subject(:commits) { result.objects('commits') }
...@@ -122,7 +122,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do ...@@ -122,7 +122,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do
describe 'search for blobs in non-default branch' do describe 'search for blobs in non-default branch' do
let(:project) { create(:project, :public, :repository, :repository_private) } let(:project) { create(:project, :public, :repository, :repository_private) }
let(:result) { described_class.new(user, 'initial', project.id, 'test') } let(:result) { described_class.new(user, 'initial', project, 'test') }
subject(:blobs) { result.objects('blobs') } subject(:blobs) { result.objects('blobs') }
...@@ -149,7 +149,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do ...@@ -149,7 +149,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do
end end
it 'does not list project confidential issues for non project members' do it 'does not list project confidential issues for non project members' do
results = described_class.new(non_member, query, project.id) results = described_class.new(non_member, query, project)
issues = results.objects('issues') issues = results.objects('issues')
expect(issues).to include issue expect(issues).to include issue
...@@ -159,7 +159,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do ...@@ -159,7 +159,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do
end end
it 'lists project confidential issues for author' do it 'lists project confidential issues for author' do
results = described_class.new(author, query, project.id) results = described_class.new(author, query, project)
issues = results.objects('issues') issues = results.objects('issues')
expect(issues).to include issue expect(issues).to include issue
...@@ -169,7 +169,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do ...@@ -169,7 +169,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do
end end
it 'lists project confidential issues for assignee' do it 'lists project confidential issues for assignee' do
results = described_class.new(assignee, query, project.id) results = described_class.new(assignee, query, project)
issues = results.objects('issues') issues = results.objects('issues')
expect(issues).to include issue expect(issues).to include issue
...@@ -181,7 +181,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do ...@@ -181,7 +181,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do
it 'lists project confidential issues for project members' do it 'lists project confidential issues for project members' do
project.add_developer(member) project.add_developer(member)
results = described_class.new(member, query, project.id) results = described_class.new(member, query, project)
issues = results.objects('issues') issues = results.objects('issues')
expect(issues).to include issue expect(issues).to include issue
...@@ -193,7 +193,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do ...@@ -193,7 +193,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do
it 'does not list project confidential issues for project members with guest role' do it 'does not list project confidential issues for project members with guest role' do
project.add_guest(member) project.add_guest(member)
results = described_class.new(member, query, project.id) results = described_class.new(member, query, project)
issues = results.objects('issues') issues = results.objects('issues')
expect(issues).to include issue expect(issues).to include issue
...@@ -203,7 +203,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do ...@@ -203,7 +203,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do
end end
it 'lists all project issues for admin' do it 'lists all project issues for admin' do
results = described_class.new(admin, query, project.id) results = described_class.new(admin, query, project)
issues = results.objects('issues') issues = results.objects('issues')
expect(issues).to include issue expect(issues).to include issue
...@@ -214,7 +214,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do ...@@ -214,7 +214,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do
end end
context 'user search' do context 'user search' do
subject(:results) { described_class.new(user, project.owner.username, project.id) } subject(:results) { described_class.new(user, project.owner.username, project) }
before do before do
expect(Gitlab::ProjectSearchResults).to receive(:new).and_call_original expect(Gitlab::ProjectSearchResults).to receive(:new).and_call_original
......
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