From d460d2ebadaebca37111393257546c9c4a3a2417 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 12 May 2018 12:41:25 -0700 Subject: [PATCH] Use pluck for async reindex to avoid loading records in memory - #1134 --- lib/searchkick/bulk_indexer.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/searchkick/bulk_indexer.rb b/lib/searchkick/bulk_indexer.rb index 580c1c9..451c250 100644 --- a/lib/searchkick/bulk_indexer.rb +++ b/lib/searchkick/bulk_indexer.rb @@ -14,7 +14,7 @@ module Searchkick end if batch - import_or_update relation.to_a, method_name, async + import_or_update relation, method_name, async Searchkick.with_redis { |r| r.srem(batches_key, batch_id) } if batch_id elsif full && async full_reindex_async(relation) @@ -58,11 +58,13 @@ module Searchkick private def import_or_update(records, method_name, async) + records = async ? records.pluck(:id) : records.to_a + if records.any? if async Searchkick::BulkReindexJob.perform_later( - class_name: records.first.class.name, - record_ids: records.map(&:id), + class_name: records.name, + record_ids: records, index_name: index.name, method_name: method_name ? method_name.to_s : nil ) -- libgit2 0.21.0