10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'app/workers/good_job/elasticsearch_reindex.rb', line 10
def perform(index_class_name, index_name)
batch_size = (Rails.application.config.x.full_reindex_batch_size&.to_i).presence || 100
index_class = index_class_name.constantize
start_time = Time.current
ActiveRecord::Base.transaction do
Cursor.execute(name: index_name, sql: index_class.active_record.select(:id).to_sql) do |cursor|
while (records = cursor.next(10_000)) do
record_ids = records.map { |record| record["id"] }
args = record_ids.each_slice(batch_size).map do |ids|
[index_class_name, index_name, ids]
end
GoodJob::ElasticsearchProcessBatch.perform_deferred_bulk(args)
end
end
end
GoodJob::ElasticsearchOnFinishReindex.perform_deferred(index_class_name, index_name, start_time)
end
|