Commit f0680859a441aa0b937efd2f6cb9d10eb0f04a8f
1 parent
85413878
Exists in
master
and in
19 other branches
Added async option to record reindex
Showing
2 changed files
with
17 additions
and
7 deletions
Show diff stats
lib/searchkick/model.rb
... | ... | @@ -84,17 +84,26 @@ module Searchkick |
84 | 84 | after_destroy callback_name, if: proc { self.class.search_callbacks? } |
85 | 85 | end |
86 | 86 | |
87 | - def reindex(method_name = nil, refresh: false) | |
88 | - if method_name | |
89 | - self.class.searchkick_index.bulk_update([self], method_name) | |
87 | + def reindex(method_name = nil, refresh: false, async: false) | |
88 | + if async | |
89 | + if method_name | |
90 | + raise Searchkick::Error, "Partial updates not yet supported with async" | |
91 | + else | |
92 | + self.class.searchkick_index.reindex_record_async(self) | |
93 | + end | |
90 | 94 | else |
91 | - self.class.searchkick_index.reindex_record(self) | |
95 | + if method_name | |
96 | + self.class.searchkick_index.bulk_update([self], method_name) | |
97 | + else | |
98 | + self.class.searchkick_index.reindex_record(self) | |
99 | + end | |
100 | + self.class.searchkick_index.refresh if refresh | |
92 | 101 | end |
93 | - self.class.searchkick_index.refresh if refresh | |
94 | 102 | end unless method_defined?(:reindex) |
95 | 103 | |
104 | + # TODO remove this method in next major version | |
96 | 105 | def reindex_async |
97 | - self.class.searchkick_index.reindex_record_async(self) | |
106 | + reindex(async: true) | |
98 | 107 | end unless method_defined?(:reindex_async) |
99 | 108 | |
100 | 109 | def similar(options = {}) | ... | ... |
test/test_helper.rb
... | ... | @@ -372,7 +372,8 @@ class Animal |
372 | 372 | searchkick \ |
373 | 373 | text_start: [:name], |
374 | 374 | suggest: [:name], |
375 | - index_name: -> { "#{name.tableize}-#{Date.today.year}" } | |
375 | + index_name: -> { "#{name.tableize}-#{Date.today.year}" }, | |
376 | + callbacks: :async | |
376 | 377 | # wordnet: true |
377 | 378 | end |
378 | 379 | ... | ... |