Include source namespace when indexing users into Elasticsearch

What does this MR do and why?

Includes member => source => namespace when preloading user data for indexing into Elasticsearch. This gets rid of an additional namespace query that's needed when a user has a project namespace.

Before

Source is being preloaded but we see additional queries for namespaces:

image

After

Now the namespace of source is also preloaded and the only additional queries are to recursively/linearly determine namespace ancestors:

image

How to set up and validate locally

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

items = Elastic::ProcessBookkeepingService.queued_items
refs = service.send(:deserialize_all, items.values.flatten(1))

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

Take note of the queries before the first >>>>>>>>>>> which is the preloading. Any queries after that are additional queries.

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 #390267 (closed)

Edited by Madelein van Niekerk

Merge request reports

Loading