Commit 3b8e25c5afb4af818f5e7bbc01dcbb44d00a5304
1 parent
db6367cd
Exists in
master
and in
2 other branches
DRY code [skip ci]
Showing
2 changed files
with
15 additions
and
18 deletions
Show diff stats
lib/searchkick/bulk_indexer.rb
... | ... | @@ -22,20 +22,25 @@ module Searchkick |
22 | 22 | |
23 | 23 | # determine which records to delete |
24 | 24 | delete_ids = record_ids - records.map { |r| r.id.to_s } |
25 | - delete_records = delete_ids.map do |id| | |
26 | - m = klass.new | |
27 | - m.id = id | |
28 | - if routing[id] | |
29 | - m.define_singleton_method(:search_routing) do | |
30 | - routing[id] | |
31 | - end | |
25 | + delete_records = | |
26 | + delete_ids.map do |id| | |
27 | + construct_record(klass, id, routing[id]) | |
32 | 28 | end |
33 | - m | |
34 | - end | |
35 | 29 | |
36 | 30 | import_inline(records, delete_records, method_name: nil) |
37 | 31 | end |
38 | 32 | |
33 | + def construct_record(klass, id, routing) | |
34 | + record = klass.new | |
35 | + record.id = id | |
36 | + if routing | |
37 | + record.define_singleton_method(:search_routing) do | |
38 | + routing | |
39 | + end | |
40 | + end | |
41 | + record | |
42 | + end | |
43 | + | |
39 | 44 | def import_scope(relation, resume: false, method_name: nil, async: false, full: false, scope: nil, mode: nil) |
40 | 45 | if scope |
41 | 46 | relation = relation.send(scope) | ... | ... |
lib/searchkick/reindex_v2_job.rb
... | ... | @@ -23,15 +23,7 @@ module Searchkick |
23 | 23 | nil |
24 | 24 | end |
25 | 25 | |
26 | - unless record | |
27 | - record = model.new | |
28 | - record.id = id | |
29 | - if routing | |
30 | - record.define_singleton_method(:search_routing) do | |
31 | - routing | |
32 | - end | |
33 | - end | |
34 | - end | |
26 | + record ||= model.searchkick_index.send(:bulk_indexer).construct_record(model, id, routing) | |
35 | 27 | |
36 | 28 | RecordIndexer.new(record).reindex(method_name, mode: :inline) |
37 | 29 | end | ... | ... |