Commit b35de57e authored by Dmitry Gruzd's avatar Dmitry Gruzd

Merge branch '300203-global-search-timeout-page' into 'master'

Global Search - Timeout Page

See merge request gitlab-org/gitlab!65085
parents 56bb9cad c316f374
...@@ -16,6 +16,8 @@ class SearchController < ApplicationController ...@@ -16,6 +16,8 @@ class SearchController < ApplicationController
search_term_present && !params[:project_id].present? search_term_present && !params[:project_id].present?
end end
rescue_from ActiveRecord::QueryCanceled, with: :render_timeout
layout 'search' layout 'search'
feature_category :global_search feature_category :global_search
...@@ -150,6 +152,15 @@ class SearchController < ApplicationController ...@@ -150,6 +152,15 @@ class SearchController < ApplicationController
redirect_to new_user_session_path, alert: _('You must be logged in to search across all of GitLab') redirect_to new_user_session_path, alert: _('You must be logged in to search across all of GitLab')
end end
def render_timeout(exception)
raise exception unless action_name.to_sym == :show
log_exception(exception)
@timeout = true
render status: :request_timeout
end
end end
SearchController.prepend_mod_with('SearchController') SearchController.prepend_mod_with('SearchController')
...@@ -301,7 +301,7 @@ module SearchHelper ...@@ -301,7 +301,7 @@ module SearchHelper
if @scope == scope if @scope == scope
li_class = 'active' li_class = 'active'
count = @search_results.formatted_count(scope) count = @timeout ? 0 : @search_results.formatted_count(scope)
else else
badge_class = 'js-search-count hidden' badge_class = 'js-search-count hidden'
badge_data = { url: search_count_path(search_params) } badge_data = { url: search_count_path(search_params) }
......
- search_bar_classes = 'search-sidebar gl-display-flex gl-flex-direction-column gl-mr-4' - search_bar_classes = 'search-sidebar gl-display-flex gl-flex-direction-column gl-mr-4'
= render_if_exists 'shared/promotions/promote_advanced_search'
= render partial: 'search/results_status', locals: { search_service: @search_service } unless @search_objects.to_a.empty?
- if @search_objects.to_a.empty? .results.gl-md-display-flex.gl-mt-3
.gl-md-display-flex - if %w(issues merge_requests).include?(@scope)
- if %w(issues merge_requests).include?(@scope) #js-search-sidebar{ class: search_bar_classes }
#js-search-sidebar{ class: search_bar_classes } .gl-w-full.gl-flex-grow-1.gl-overflow-x-hidden
.gl-w-full.gl-flex-grow-1.gl-overflow-x-hidden - if @timeout
= render partial: "search/results/timeout"
- elsif @search_objects.to_a.empty?
= render partial: "search/results/empty" = render partial: "search/results/empty"
= render_if_exists 'shared/promotions/promote_advanced_search' - else
- else
= render partial: 'search/results_status', locals: { search_service: @search_service }
= render_if_exists 'shared/promotions/promote_advanced_search'
.results.gl-md-display-flex.gl-mt-3
- if %w(issues merge_requests).include?(@scope)
#js-search-sidebar{ class: search_bar_classes }
.gl-w-full.gl-flex-grow-1.gl-overflow-x-hidden
- if @scope == 'commits' - if @scope == 'commits'
%ul.content-list.commit-list %ul.content-list.commit-list
= render partial: "search/results/commit", collection: @search_objects = render partial: "search/results/commit", collection: @search_objects
......
.gl-display-flex.gl-flex-direction-column.gl-align-items-center
%div
.svg-content.svg-150
= image_tag 'illustrations/search-timeout-md.svg'
%div
%h4.gl-text-center.gl-font-weight-bold= _('Your search timed out')
%p.gl-text-center= _('To resolve this, try to:')
%ul
%li= html_escape(_('Refine your search criteria (select a %{strong_open}group%{strong_close} and %{strong_open}project%{strong_close} when possible)')) % { strong_open: '<strong>'.html_safe, strong_close: '</strong>'.html_safe }
%li= html_escape(_('Use double quotes for multiple keywords, such as %{code_open}"your search"%{code_close}')) % { code_open: '<code>'.html_safe, code_close: '</code>'.html_safe }
...@@ -24,6 +24,7 @@ RSpec.describe 'User searches for epics', :js do ...@@ -24,6 +24,7 @@ RSpec.describe 'User searches for epics', :js do
end end
include_examples 'top right search form' include_examples 'top right search form'
include_examples 'search timeouts', 'epics'
it 'finds an epic' do it 'finds an epic' do
search_for_epic(epic1.title) search_for_epic(epic1.title)
......
...@@ -26953,6 +26953,9 @@ msgstr "" ...@@ -26953,6 +26953,9 @@ msgstr ""
msgid "References" msgid "References"
msgstr "" msgstr ""
msgid "Refine your search criteria (select a %{strong_open}group%{strong_close} and %{strong_open}project%{strong_close} when possible)"
msgstr ""
msgid "Refresh" msgid "Refresh"
msgstr "" msgstr ""
...@@ -34218,6 +34221,9 @@ msgstr "" ...@@ -34218,6 +34221,9 @@ msgstr ""
msgid "To receive alerts from manually configured Prometheus services, add the following URL and Authorization key to your Prometheus webhook config file. Learn more about %{linkStart}configuring Prometheus%{linkEnd} to send alerts to GitLab." msgid "To receive alerts from manually configured Prometheus services, add the following URL and Authorization key to your Prometheus webhook config file. Learn more about %{linkStart}configuring Prometheus%{linkEnd} to send alerts to GitLab."
msgstr "" msgstr ""
msgid "To resolve this, try to:"
msgstr ""
msgid "To run CI/CD pipelines with JetBrains TeamCity, input the GitLab project details in the TeamCity project Version Control Settings." msgid "To run CI/CD pipelines with JetBrains TeamCity, input the GitLab project details in the TeamCity project Version Control Settings."
msgstr "" msgstr ""
...@@ -35474,6 +35480,9 @@ msgstr "" ...@@ -35474,6 +35480,9 @@ msgstr ""
msgid "Use custom color #FF0000" msgid "Use custom color #FF0000"
msgstr "" msgstr ""
msgid "Use double quotes for multiple keywords, such as %{code_open}\"your search\"%{code_close}"
msgstr ""
msgid "Use hashed storage" msgid "Use hashed storage"
msgstr "" msgstr ""
...@@ -38048,6 +38057,9 @@ msgstr "" ...@@ -38048,6 +38057,9 @@ msgstr ""
msgid "Your search didn't match any commits. Try a different query." msgid "Your search didn't match any commits. Try a different query."
msgstr "" msgstr ""
msgid "Your search timed out"
msgstr ""
msgid "Your sign-in page is %{url}." msgid "Your sign-in page is %{url}."
msgstr "" msgstr ""
......
...@@ -37,6 +37,7 @@ RSpec.describe 'User searches for code' do ...@@ -37,6 +37,7 @@ RSpec.describe 'User searches for code' do
end end
include_examples 'top right search form' include_examples 'top right search form'
include_examples 'search timeouts', 'blobs'
it 'finds code' do it 'finds code' do
fill_in('dashboard_search', with: 'rspec') fill_in('dashboard_search', with: 'rspec')
......
...@@ -13,6 +13,8 @@ RSpec.describe 'User searches for comments' do ...@@ -13,6 +13,8 @@ RSpec.describe 'User searches for comments' do
visit(project_path(project)) visit(project_path(project))
end end
include_examples 'search timeouts', 'notes'
context 'when a comment is in commits' do context 'when a comment is in commits' do
context 'when comment belongs to an invalid commit' do context 'when comment belongs to an invalid commit' do
let(:comment) { create(:note_on_commit, author: user, project: project, commit_id: 12345678, note: 'Bug here') } let(:comment) { create(:note_on_commit, author: user, project: project, commit_id: 12345678, note: 'Bug here') }
......
...@@ -14,6 +14,8 @@ RSpec.describe 'User searches for commits', :js do ...@@ -14,6 +14,8 @@ RSpec.describe 'User searches for commits', :js do
visit(search_path(project_id: project.id)) visit(search_path(project_id: project.id))
end end
include_examples 'search timeouts', 'commits'
context 'when searching by SHA' do context 'when searching by SHA' do
it 'finds a commit and redirects to its page' do it 'finds a commit and redirects to its page' do
submit_search(sha) submit_search(sha)
......
...@@ -23,6 +23,7 @@ RSpec.describe 'User searches for issues', :js do ...@@ -23,6 +23,7 @@ RSpec.describe 'User searches for issues', :js do
end end
include_examples 'top right search form' include_examples 'top right search form'
include_examples 'search timeouts', 'issues'
it 'finds an issue' do it 'finds an issue' do
search_for_issue(issue1.title) search_for_issue(issue1.title)
......
...@@ -22,6 +22,7 @@ RSpec.describe 'User searches for merge requests', :js do ...@@ -22,6 +22,7 @@ RSpec.describe 'User searches for merge requests', :js do
end end
include_examples 'top right search form' include_examples 'top right search form'
include_examples 'search timeouts', 'merge_requests'
it 'finds a merge request' do it 'finds a merge request' do
search_for_mr(merge_request1.title) search_for_mr(merge_request1.title)
......
...@@ -16,6 +16,7 @@ RSpec.describe 'User searches for milestones', :js do ...@@ -16,6 +16,7 @@ RSpec.describe 'User searches for milestones', :js do
end end
include_examples 'top right search form' include_examples 'top right search form'
include_examples 'search timeouts', 'milestones'
it 'finds a milestone' do it 'finds a milestone' do
fill_in('dashboard_search', with: milestone1.title) fill_in('dashboard_search', with: milestone1.title)
......
...@@ -12,6 +12,7 @@ RSpec.describe 'User searches for projects', :js do ...@@ -12,6 +12,7 @@ RSpec.describe 'User searches for projects', :js do
end end
include_examples 'top right search form' include_examples 'top right search form'
include_examples 'search timeouts', 'projects'
it 'finds a project' do it 'finds a project' do
visit(search_path) visit(search_path)
......
...@@ -11,6 +11,8 @@ RSpec.describe 'User searches for users' do ...@@ -11,6 +11,8 @@ RSpec.describe 'User searches for users' do
sign_in(user1) sign_in(user1)
end end
include_examples 'search timeouts', 'users'
context 'when on the dashboard' do context 'when on the dashboard' do
it 'finds the user', :js do it 'finds the user', :js do
visit dashboard_projects_path visit dashboard_projects_path
......
...@@ -15,6 +15,7 @@ RSpec.describe 'User searches for wiki pages', :js do ...@@ -15,6 +15,7 @@ RSpec.describe 'User searches for wiki pages', :js do
end end
include_examples 'top right search form' include_examples 'top right search form'
include_examples 'search timeouts', 'wiki_blobs'
shared_examples 'search wiki blobs' do shared_examples 'search wiki blobs' do
it 'finds a page' do it 'finds a page' do
......
# frozen_string_literal: true
RSpec.shared_examples 'search timeouts' do |scope|
context 'when search times out' do
before do
allow_next_instance_of(SearchService) do |service|
allow(service).to receive(:search_objects).and_raise(ActiveRecord::QueryCanceled)
end
visit(search_path(search: 'test', scope: scope))
end
it 'renders timeout information' do
expect(page).to have_content('Your search timed out')
end
it 'sets tab count to 0' do
expect(page.find('.search-filter .active')).to have_text('0')
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