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 ...@@ -160,19 +160,21 @@ describe API::Search do
context 'for issues scope', :sidekiq_inline do context 'for issues scope', :sidekiq_inline do
before do before do
create_list(:issue, 4, project: project) create_list(:issue, 2, project: project)
ensure_elasticsearch_index! ensure_elasticsearch_index!
end end
it 'avoids N+1 queries' do it 'avoids N+1 queries' do
control = ActiveRecord::QueryRecorder.new { get api(endpoint, user), params: { scope: 'issues', search: '*' } } 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! ensure_elasticsearch_index!
# Some N+1 queries still exist # 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 end
it_behaves_like 'pagination', scope: 'issues' it_behaves_like 'pagination', scope: 'issues'
......
...@@ -21,8 +21,9 @@ module API ...@@ -21,8 +21,9 @@ module API
}.freeze }.freeze
SCOPE_PRELOAD_METHOD = { SCOPE_PRELOAD_METHOD = {
merge_requests: :with_api_entity_associations, merge_requests: :with_api_entity_associations,
projects: :with_api_entity_associations projects: :with_api_entity_associations,
issues: :with_api_entity_associations
}.freeze }.freeze
def search(additional_params = {}) 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