From 0fa5260f1d1e99bcd0429cba09140c039a3d9d5a Mon Sep 17 00:00:00 2001 From: Mark Chao Date: Tue, 16 Oct 2018 13:56:13 +0800 Subject: Allow search results to accept project_id This gives flexiblity to avoid duplicated query of Project. --- lib/gitlab/search_results.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/gitlab/search_results.rb b/lib/gitlab/search_results.rb index b46c18c4364..458737f31eb 100644 --- a/lib/gitlab/search_results.rb +++ b/lib/gitlab/search_results.rb @@ -18,6 +18,11 @@ module Gitlab @data = encode_utf8(opts.fetch(:data, nil)) @per_page = opts.fetch(:per_page, 20) @project = opts.fetch(:project, nil) + # Some caller does not have project object (e.g. elastic search), + # yet they can trigger many calls in one go, + # causing duplicated queries. + # Allow those to just pass project_id instead. + @project_id = opts.fetch(:project_id, nil) end def path @@ -25,7 +30,7 @@ module Gitlab end def project_id - @project&.id + @project_id || @project&.id end def present -- cgit v1.2.1