diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-03-19 16:00:55 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-03-19 16:00:55 +0000 |
commit | 8b723776ac98dc84d4e0f93302602e3949fda5c6 (patch) | |
tree | 2838af570affc7918e4790a2d89d087a17e25c81 | |
parent | 479cf8927029f911b998091d8279612ff0cbfcef (diff) | |
parent | 9487c3703757ba013923125c4fe7774b9cea6f9b (diff) | |
download | gitlab-ce-8b723776ac98dc84d4e0f93302602e3949fda5c6.tar.gz |
Merge branch 'fix_trigger_search' into 'master'
Only trigger search if search string is present
This is a follow up for !296 to prevent the search function from being executed while the query is nil.
Problem was this:
When the search is called, the search controller gets 2 requests.
```
{"action"=>"show", "controller"=>"search"}
```
and
```
{"utf8"=>"✓",
"search"=>"proj",
"project_id"=>"",
"group_id"=>"",
"snippets"=>"",
"scope"=>"",
"button"=>"",
"action"=>"show",
"controller"=>"search"}
```
Obviously it doesn't make sense to execute the search for the first request, since that one doesn't have a scope or a search string.
Please review this carefully since this modifies the search and may break things i can't think of.
@dzaporozhets While this fixes the root cause for the failing test, I think we should keep your fix in as a failsafe. What do you think of this?
See merge request !302
-rw-r--r-- | app/controllers/search_controller.rb | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 55926a1ed22..a3284c82d3f 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -2,34 +2,34 @@ class SearchController < ApplicationController include SearchHelper def show + return if params[:search].nil? || params[:search].blank? @project = Project.find_by(id: params[:project_id]) if params[:project_id].present? @group = Group.find_by(id: params[:group_id]) if params[:group_id].present? @scope = params[:scope] @show_snippets = params[:snippets].eql? 'true' - @search_results = if @project - return access_denied! unless can?(current_user, :download_code, @project) - - unless %w(blobs notes issues merge_requests wiki_blobs). - include?(@scope) - @scope = 'blobs' - end - - Search::ProjectService.new(@project, current_user, params).execute - elsif @show_snippets - unless %w(snippet_blobs snippet_titles).include?(@scope) - @scope = 'snippet_blobs' - end - - Search::SnippetService.new(current_user, params).execute - else - unless %w(projects issues merge_requests).include?(@scope) - @scope = 'projects' - end - - Search::GlobalService.new(current_user, params).execute - end - + @search_results = + if @project + return access_denied! unless can?(current_user, :download_code, @project) + + unless %w(blobs notes issues merge_requests wiki_blobs). + include?(@scope) + @scope = 'blobs' + end + + Search::ProjectService.new(@project, current_user, params).execute + elsif @show_snippets + unless %w(snippet_blobs snippet_titles).include?(@scope) + @scope = 'snippet_blobs' + end + + Search::SnippetService.new(current_user, params).execute + else + unless %w(projects issues merge_requests).include?(@scope) + @scope = 'projects' + end + Search::GlobalService.new(current_user, params).execute + end @objects = @search_results.objects(@scope, params[:page]) end |