Commit ab8cbdc1 authored by Alishan Ladhani's avatar Alishan Ladhani

Use scope for issue search preloads

parent 0f4a3165
---
title: Improve performance of Advanced Search API (Issues scope) by preloading more associations
merge_request: 30778
author:
type: performance
......@@ -160,19 +160,21 @@ describe API::Search do
context 'for issues scope', :sidekiq_inline do
before do
create_list(:issue, 4, project: project)
create_list(:issue, 2, project: project)
ensure_elasticsearch_index!
end
it 'avoids N+1 queries' do
control = ActiveRecord::QueryRecorder.new { get api(endpoint, user), params: { scope: 'issues', search: '*' } }
new_issues = create_list(:issue, 4, project: project)
create_list(:issue, 2, project: project)
create_list(:issue, 2, project: create(:project, group: group))
create_list(:issue, 2)
ensure_elasticsearch_index!
# Some N+1 queries still exist
expect { get api(endpoint, user), params: { scope: 'issues', search: '*' } }.not_to exceed_query_limit(control.count + new_issues.count * 4)
expect { get api(endpoint, user), params: { scope: 'issues', search: '*' } }.not_to exceed_query_limit(control.count + 2)
end
it_behaves_like 'pagination', scope: 'issues'
......
......@@ -21,8 +21,9 @@ module API
}.freeze
SCOPE_PRELOAD_METHOD = {
merge_requests: :with_api_entity_associations,
projects: :with_api_entity_associations
merge_requests: :with_api_entity_associations,
projects: :with_api_entity_associations,
issues: :with_api_entity_associations
}.freeze
def search(additional_params = {})
......
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