Commit 4713940e authored by Stan Hu's avatar Stan Hu

Merge branch '324745-preload-projects-for-elasticsearch-indexing' into 'master'

Remove N+1 DB queries from indexing projects in Elasticsearch

See merge request gitlab-org/gitlab!57794
parents 4156030a dae256ee
---
title: Remove N+1 DB queries from indexing projects in Elasticsearch
merge_request: 57794
author:
type: performance
...@@ -49,6 +49,12 @@ module Elastic ...@@ -49,6 +49,12 @@ module Elastic
search(query_hash, options) search(query_hash, options)
end end
# rubocop: disable CodeReuse/ActiveRecord
def preload_indexing_data(relation)
relation.includes(:project_feature, :route)
end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
...@@ -209,6 +209,20 @@ RSpec.describe Elastic::ProcessBookkeepingService, :clean_gitlab_redis_shared_st ...@@ -209,6 +209,20 @@ RSpec.describe Elastic::ProcessBookkeepingService, :clean_gitlab_redis_shared_st
end end
context 'N+1 queries' do context 'N+1 queries' do
it 'does not have N+1 queries for projects' do
projects = create_list(:project, 2)
described_class.track!(*projects)
control = ActiveRecord::QueryRecorder.new(skip_cached: false) { described_class.new.execute }
projects += create_list(:project, 3)
described_class.track!(*projects)
expect { described_class.new.execute }.not_to exceed_all_query_limit(control)
end
it 'does not have N+1 queries for notes' do it 'does not have N+1 queries for notes' do
notes = [] notes = []
......
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