diff --git a/app/controllers/concerns/issuable_collections_action.rb b/app/controllers/concerns/issuable_collections_action.rb index b8249345a5481980061b4d6d410f1c39405e9204..13298b9065de849b28ec2843a4b29f48ac7cef30 100644 --- a/app/controllers/concerns/issuable_collections_action.rb +++ b/app/controllers/concerns/issuable_collections_action.rb @@ -2,6 +2,7 @@ module IssuableCollectionsAction extend ActiveSupport::Concern + include GracefulTimeoutHandling include IssuableCollections include IssuesCalendar @@ -33,6 +34,10 @@ def merge_requests @merge_requests = issuables_collection.page(params[:page]) @issuable_meta_data = Gitlab::IssuableMetadata.new(current_user, @merge_requests).data + rescue ActiveRecord::QueryCanceled => exception # rubocop:disable Database/RescueQueryCanceled + log_exception(exception) + + @search_timeout_occurred = true end # rubocop:enable Gitlab/ModuleWithInstanceVariables diff --git a/app/views/dashboard/merge_requests.html.haml b/app/views/dashboard/merge_requests.html.haml index c921375edd1b7baf56a999f8bc06d818f90018a5..97fb35b28ab0cac8b3d1cf415b3a6aa953ecde0b 100644 --- a/app/views/dashboard/merge_requests.html.haml +++ b/app/views/dashboard/merge_requests.html.haml @@ -19,5 +19,7 @@ - if current_user && @no_filters_set = render 'shared/dashboard/no_filter_selected' +- elsif @search_timeout_occurred + = render 'shared/dashboard/search_timeout_occurred' - else = render 'shared/merge_requests' diff --git a/app/views/shared/dashboard/_search_timeout_occurred.html.haml b/app/views/shared/dashboard/_search_timeout_occurred.html.haml new file mode 100644 index 0000000000000000000000000000000000000000..4b6331ee9865651c34987c0a07ff45c37e0b335c --- /dev/null +++ b/app/views/shared/dashboard/_search_timeout_occurred.html.haml @@ -0,0 +1,8 @@ +.row.empty-state.text-center + .col-12 + .svg-130.gl-mt-3 + = image_tag 'illustrations/issue-dashboard_results-without-filter.svg' + .col-12 + .text-content + %h4 + = _("Too many results to display. Edit your search or add a filter.") diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 1ff9b6586f2656ce4f998a99da7abf1055dd4d1e..5e9450effd43c9fe9697ca387f04194f0f22f663 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -44211,6 +44211,9 @@ msgstr "" msgid "Too many references. Quick actions are limited to at most %{max_count} user references" msgstr "" +msgid "Too many results to display. Edit your search or add a filter." +msgstr "" + msgid "Too many users found. Quick actions are limited to at most %{max_count} users" msgstr "" diff --git a/spec/controllers/dashboard_controller_spec.rb b/spec/controllers/dashboard_controller_spec.rb index ea12b0c5ad795b24cd315eb382c059fb81a9b96a..d19145058e78d2cc17e5a1eb8b94c00a7c853c7c 100644 --- a/spec/controllers/dashboard_controller_spec.rb +++ b/spec/controllers/dashboard_controller_spec.rb @@ -46,6 +46,37 @@ describe 'GET merge requests' do it_behaves_like 'issuables list meta-data', :merge_request, :merge_requests it_behaves_like 'issuables requiring filter', :merge_requests + + context 'when an ActiveRecord::QueryCanceled is raised' do + before do + allow_next_instance_of(Gitlab::IssuableMetadata) do |instance| + allow(instance).to receive(:data).and_raise(ActiveRecord::QueryCanceled) + end + end + + it 'sets :search_timeout_occurred' do + get :merge_requests, params: { author_id: user.id } + + expect(response).to have_gitlab_http_status(:ok) + expect(assigns(:search_timeout_occurred)).to eq(true) + end + + context 'rendering views' do + render_views + + it 'shows error message' do + get :merge_requests, params: { author_id: user.id } + + expect(response.body).to have_content('Too many results to display. Edit your search or add a filter.') + end + end + + it 'logs the exception' do + expect(Gitlab::ErrorTracking).to receive(:track_exception).and_call_original + + get :merge_requests, params: { author_id: user.id } + end + end end end