Skip to content

Fixes N+1 queries when users are indexed into elasticsearch

What does this MR do and why?

Addresses N+1 queries when indexing users by preloading necessary data.

Before

After

Maximum of 5 queries with no N+1 queries.

How to set up and validate locally

service = Elastic::ProcessBookkeepingService.new
Elastic::ProcessBookkeepingService.track!(*User.take(5))
ActiveRecord::Base.logger = Logger.new $stdout  

items = Elastic::ProcessBookkeepingService.queued_items
refs = service.send(:deserialize_all, items.first.last)

refs.preload_database_records.each do |ref|
  puts ">>>>>>>>>>> #{ref.klass.to_s}"
  service.send(:submit_document, ref)
end;nil

Note the data being preloaded before the first >>>>>>>>>>> and that the only data being queried afterwards is to determine namespace ancestry for the user's memberships.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #390228 (closed)

Edited by Madelein van Niekerk

Merge request reports