Commit fd9ca353 authored by Tan Le's avatar Tan Le

Improve loading time for large number of events

We have noted large compute time spent on `#define_method` by
`BatchLoader` and this has contribute to the slowness on large CSV
import queries. This change will hopefully reduce these up-front costs
and as a result, reduce total processing time.

More information about `replace_methods` option can be found at
https://github.com/exAspArk/batch-loader#replacing-methods
parent d4dee59e
......@@ -65,8 +65,8 @@ class AuditEvent < ApplicationRecord
end
def lazy_author
BatchLoader.for(author_id).batch(default_value: default_author_value) do |author_ids, loader|
User.where(id: author_ids).find_each do |user|
BatchLoader.for(author_id).batch(default_value: default_author_value, replace_methods: false) do |author_ids, loader|
User.select(:id, :name, :username).where(id: author_ids).find_each do |user|
loader.call(user.id, user)
end
end
......
......@@ -47,7 +47,7 @@ module EE
def lazy_entity
BatchLoader.for(entity_id)
.batch(
key: entity_type, default_value: ::Gitlab::Audit::NullEntity.new
key: entity_type, default_value: ::Gitlab::Audit::NullEntity.new, replace_methods: false
) do |ids, loader, args|
model = Object.const_get(args[:key], false)
model.where(id: ids).find_each { |record| loader.call(record.id, record) }
......
---
title: Reduce load time of large number of audit events
merge_request: 43248
author:
type: performance
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