Commit 7bc3d4b7bc28d210e75d72257dfb170160c93de0
1 parent
ef1e6c8e
Exists in
master
and in
2 other branches
Improved split [skip ci]
Showing
2 changed files
with
11 additions
and
6 deletions
Show diff stats
lib/searchkick/bulk_record_indexer.rb
... | ... | @@ -31,10 +31,8 @@ module Searchkick |
31 | 31 | end |
32 | 32 | end |
33 | 33 | |
34 | - # TODO figure out better place for logic | |
35 | - def import_queue(klass, record_ids) | |
36 | - # separate routing from id | |
37 | - routing = Hash[record_ids.map { |r| r.split(/(?<!\|)\|(?!\|)/, 2).map { |v| v.gsub("||", "|") } }] | |
34 | + def reindex_items(klass, items) | |
35 | + routing = items.to_h { |r| [r[:id], r[:routing]] } | |
38 | 36 | record_ids = routing.keys |
39 | 37 | |
40 | 38 | scope = Searchkick.load_records(klass, record_ids) | ... | ... |
lib/searchkick/process_batch_job.rb
... | ... | @@ -5,8 +5,15 @@ module Searchkick |
5 | 5 | def perform(class_name:, record_ids:, index_name: nil) |
6 | 6 | klass = class_name.constantize |
7 | 7 | index = klass.searchkick_index(name: index_name) |
8 | - # TODO move import_queue logic | |
9 | - index.send(:bulk_record_indexer).import_queue(klass, record_ids) | |
8 | + | |
9 | + items = | |
10 | + record_ids.map do |r| | |
11 | + parts = r.split(/(?<!\|)\|(?!\|)/, 2) | |
12 | + .map { |v| v.gsub("||", "|") } | |
13 | + {id: parts[0], routing: parts[1]} | |
14 | + end | |
15 | + | |
16 | + index.send(:bulk_record_indexer).reindex_items(klass, items) | |
10 | 17 | end |
11 | 18 | end |
12 | 19 | end | ... | ... |