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
![](/-/project/278964/uploads/53367172a823aa103b46d1fcd6578dea/image.png)
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.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #390228 (closed)
Edited by Madelein van Niekerk