Commit d460d2ebadaebca37111393257546c9c4a3a2417
1 parent
289d9918
Exists in
master
and in
18 other branches
Use pluck for async reindex to avoid loading records in memory - #1134
Showing
1 changed file
with
5 additions
and
3 deletions
Show diff stats
lib/searchkick/bulk_indexer.rb
... | ... | @@ -14,7 +14,7 @@ module Searchkick |
14 | 14 | end |
15 | 15 | |
16 | 16 | if batch |
17 | - import_or_update relation.to_a, method_name, async | |
17 | + import_or_update relation, method_name, async | |
18 | 18 | Searchkick.with_redis { |r| r.srem(batches_key, batch_id) } if batch_id |
19 | 19 | elsif full && async |
20 | 20 | full_reindex_async(relation) |
... | ... | @@ -58,11 +58,13 @@ module Searchkick |
58 | 58 | private |
59 | 59 | |
60 | 60 | def import_or_update(records, method_name, async) |
61 | + records = async ? records.pluck(:id) : records.to_a | |
62 | + | |
61 | 63 | if records.any? |
62 | 64 | if async |
63 | 65 | Searchkick::BulkReindexJob.perform_later( |
64 | - class_name: records.first.class.name, | |
65 | - record_ids: records.map(&:id), | |
66 | + class_name: records.name, | |
67 | + record_ids: records, | |
66 | 68 | index_name: index.name, |
67 | 69 | method_name: method_name ? method_name.to_s : nil |
68 | 70 | ) | ... | ... |