Commit 09b7c7bcd2bd87a2c9632375b7bb7c75a38e415c
1 parent
10138016
Exists in
master
and in
19 other branches
Cleaned up reindex record code [skip ci]
Showing
1 changed file
with
14 additions
and
22 deletions
Show diff stats
lib/searchkick/record_indexer.rb
... | ... | @@ -21,7 +21,7 @@ module Searchkick |
21 | 21 | if Searchkick.callbacks_value |
22 | 22 | Searchkick.callbacks_value |
23 | 23 | else |
24 | - klass_options[:callbacks] | |
24 | + klass_options[:callbacks] || true | |
25 | 25 | end |
26 | 26 | end |
27 | 27 | |
... | ... | @@ -29,10 +29,14 @@ module Searchkick |
29 | 29 | when :queue |
30 | 30 | if method_name |
31 | 31 | raise Searchkick::Error, "Partial reindex not supported with queue option" |
32 | - else | |
33 | - index.reindex_queue.push(record.id.to_s) | |
34 | 32 | end |
33 | + | |
34 | + index.reindex_queue.push(record.id.to_s) | |
35 | 35 | when :async |
36 | + unless defined?(ActiveJob) | |
37 | + raise Searchkick::Error, "Active Job not found" | |
38 | + end | |
39 | + | |
36 | 40 | if method_name |
37 | 41 | # TODO support Mongoid and NoBrainer and non-id primary keys |
38 | 42 | Searchkick::BulkReindexJob.perform_later( |
... | ... | @@ -41,21 +45,17 @@ module Searchkick |
41 | 45 | method_name: method_name ? method_name.to_s : nil |
42 | 46 | ) |
43 | 47 | else |
44 | - reindex_record_async | |
45 | - end | |
46 | - else | |
47 | - if method_name | |
48 | - index.update_record(record, method_name) | |
49 | - else | |
50 | - reindex_record | |
48 | + Searchkick::ReindexV2Job.perform_later(record.class.name, record.id.to_s) | |
51 | 49 | end |
50 | + else # bulk, true | |
51 | + reindex_record(method_name) | |
52 | 52 | index.refresh if refresh |
53 | 53 | end |
54 | 54 | end |
55 | 55 | |
56 | 56 | private |
57 | 57 | |
58 | - def reindex_record | |
58 | + def reindex_record(method_name) | |
59 | 59 | if record.destroyed? || !record.should_index? |
60 | 60 | begin |
61 | 61 | index.remove(record) |
... | ... | @@ -63,19 +63,11 @@ module Searchkick |
63 | 63 | # do nothing |
64 | 64 | end |
65 | 65 | else |
66 | - index.store(record) | |
67 | - end | |
68 | - end | |
69 | - | |
70 | - def reindex_record_async | |
71 | - if Searchkick.callbacks_value.nil? | |
72 | - if defined?(Searchkick::ReindexV2Job) | |
73 | - Searchkick::ReindexV2Job.perform_later(record.class.name, record.id.to_s) | |
66 | + if method_name | |
67 | + index.update_record(record) | |
74 | 68 | else |
75 | - raise Searchkick::Error, "Active Job not found" | |
69 | + index.store(record) | |
76 | 70 | end |
77 | - else | |
78 | - reindex_record | |
79 | 71 | end |
80 | 72 | end |
81 | 73 | end | ... | ... |