Commit f8bac6c6 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'ali/improve-issue-search-performance' into 'master'

Advanced Search API: Eager load more issue associations to reduce N+1 queries

See merge request gitlab-org/gitlab!30233
parents 949faa28 6dd9d570
---
title: 'Advanced Search API: Eager load more issue associations to reduce N+1 queries'
merge_request: 30233
author:
type: performance
......@@ -29,7 +29,7 @@ module Gitlab
when 'projects'
eager_load(projects, page, eager: [:route, :namespace, :compliance_framework_setting])
when 'issues'
eager_load(issues, page, eager: { project: [:route, :namespace] })
eager_load(issues, page, eager: { project: [:route, :namespace], labels: [], timelogs: [], assignees: [] })
when 'merge_requests'
eager_load(merge_requests, page, eager: { target_project: [:route, :namespace] })
when 'milestones'
......
......@@ -100,6 +100,24 @@ describe API::Search do
end
end
end
context 'for issues scope', :sidekiq_inline do
before do
create_list(:issue, 4, 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)
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)
end
end
end
describe 'GET /search' do
......
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