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,7 +21,7 @@ module Searchkick | ||
21 | if Searchkick.callbacks_value | 21 | if Searchkick.callbacks_value |
22 | Searchkick.callbacks_value | 22 | Searchkick.callbacks_value |
23 | else | 23 | else |
24 | - klass_options[:callbacks] | 24 | + klass_options[:callbacks] || true |
25 | end | 25 | end |
26 | end | 26 | end |
27 | 27 | ||
@@ -29,10 +29,14 @@ module Searchkick | @@ -29,10 +29,14 @@ module Searchkick | ||
29 | when :queue | 29 | when :queue |
30 | if method_name | 30 | if method_name |
31 | raise Searchkick::Error, "Partial reindex not supported with queue option" | 31 | raise Searchkick::Error, "Partial reindex not supported with queue option" |
32 | - else | ||
33 | - index.reindex_queue.push(record.id.to_s) | ||
34 | end | 32 | end |
33 | + | ||
34 | + index.reindex_queue.push(record.id.to_s) | ||
35 | when :async | 35 | when :async |
36 | + unless defined?(ActiveJob) | ||
37 | + raise Searchkick::Error, "Active Job not found" | ||
38 | + end | ||
39 | + | ||
36 | if method_name | 40 | if method_name |
37 | # TODO support Mongoid and NoBrainer and non-id primary keys | 41 | # TODO support Mongoid and NoBrainer and non-id primary keys |
38 | Searchkick::BulkReindexJob.perform_later( | 42 | Searchkick::BulkReindexJob.perform_later( |
@@ -41,21 +45,17 @@ module Searchkick | @@ -41,21 +45,17 @@ module Searchkick | ||
41 | method_name: method_name ? method_name.to_s : nil | 45 | method_name: method_name ? method_name.to_s : nil |
42 | ) | 46 | ) |
43 | else | 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 | end | 49 | end |
50 | + else # bulk, true | ||
51 | + reindex_record(method_name) | ||
52 | index.refresh if refresh | 52 | index.refresh if refresh |
53 | end | 53 | end |
54 | end | 54 | end |
55 | 55 | ||
56 | private | 56 | private |
57 | 57 | ||
58 | - def reindex_record | 58 | + def reindex_record(method_name) |
59 | if record.destroyed? || !record.should_index? | 59 | if record.destroyed? || !record.should_index? |
60 | begin | 60 | begin |
61 | index.remove(record) | 61 | index.remove(record) |
@@ -63,19 +63,11 @@ module Searchkick | @@ -63,19 +63,11 @@ module Searchkick | ||
63 | # do nothing | 63 | # do nothing |
64 | end | 64 | end |
65 | else | 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 | else | 68 | else |
75 | - raise Searchkick::Error, "Active Job not found" | 69 | + index.store(record) |
76 | end | 70 | end |
77 | - else | ||
78 | - reindex_record | ||
79 | end | 71 | end |
80 | end | 72 | end |
81 | end | 73 | end |