Commit ec349dc1 authored by Yorick Peterse's avatar Yorick Peterse Committed by Robert Speicher

Refactor Gitlab::ProjectSearchResults

Previously this class would be given a project ID which was then used to
retrieve the corresponding Project object. However, in all cases the
Project object was already known as it was used to grab the ID to pass
to ProjectSearchResults. By just passing a Project instead we remove the
need for an extra query as well as the need for some other complexity
in this class.
parent 42fde69d
...@@ -7,7 +7,7 @@ module Search ...@@ -7,7 +7,7 @@ module Search
end end
def execute def execute
Gitlab::ProjectSearchResults.new(project.id, Gitlab::ProjectSearchResults.new(project,
params[:search], params[:search],
params[:repository_ref]) params[:repository_ref])
end end
......
...@@ -2,8 +2,8 @@ module Gitlab ...@@ -2,8 +2,8 @@ module Gitlab
class ProjectSearchResults < SearchResults class ProjectSearchResults < SearchResults
attr_reader :project, :repository_ref attr_reader :project, :repository_ref
def initialize(project_id, query, repository_ref = nil) def initialize(project, query, repository_ref = nil)
@project = Project.find(project_id) @project = project
@repository_ref = if repository_ref.present? @repository_ref = if repository_ref.present?
repository_ref repository_ref
else else
...@@ -73,7 +73,7 @@ module Gitlab ...@@ -73,7 +73,7 @@ module Gitlab
end end
def notes def notes
Note.where(project_id: limit_project_ids).user.search(query).order('updated_at DESC') project.notes.user.search(query).order('updated_at DESC')
end end
def commits def commits
...@@ -83,9 +83,5 @@ module Gitlab ...@@ -83,9 +83,5 @@ module Gitlab
project.repository.find_commits_by_message(query).compact project.repository.find_commits_by_message(query).compact
end end
end end
def limit_project_ids
[project.id]
end
end end
end end
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