Commit 6a70e1c752612334d0ec4ac188e9cf83b8dc3686
1 parent
59ac07b4
Exists in
master
and in
18 other branches
Fixed deletes with routing and callbacks - #1182
Showing
5 changed files
with
27 additions
and
2 deletions
Show diff stats
CHANGELOG.md
lib/searchkick/record_indexer.rb
... | ... | @@ -26,10 +26,13 @@ module Searchkick |
26 | 26 | raise Searchkick::Error, "Active Job not found" |
27 | 27 | end |
28 | 28 | |
29 | + routing = record.search_routing if record.destroyed? && record.respond_to?(:search_routing) | |
30 | + | |
29 | 31 | Searchkick::ReindexV2Job.perform_later( |
30 | 32 | record.class.name, |
31 | 33 | record.id.to_s, |
32 | - method_name ? method_name.to_s : nil | |
34 | + method_name ? method_name.to_s : nil, | |
35 | + routing: routing | |
33 | 36 | ) |
34 | 37 | else # bulk, inline/true/nil |
35 | 38 | reindex_record(method_name) | ... | ... |
lib/searchkick/reindex_v2_job.rb
... | ... | @@ -9,7 +9,7 @@ module Searchkick |
9 | 9 | |
10 | 10 | queue_as { Searchkick.queue_name } |
11 | 11 | |
12 | - def perform(klass, id, method_name = nil) | |
12 | + def perform(klass, id, method_name = nil, routing: nil) | |
13 | 13 | model = klass.constantize |
14 | 14 | record = |
15 | 15 | begin |
... | ... | @@ -28,6 +28,11 @@ module Searchkick |
28 | 28 | unless record |
29 | 29 | record = model.new |
30 | 30 | record.id = id |
31 | + if routing | |
32 | + record.define_singleton_method(:search_routing) do | |
33 | + routing | |
34 | + end | |
35 | + end | |
31 | 36 | end |
32 | 37 | |
33 | 38 | RecordIndexer.new(record).reindex(method_name, mode: :inline) | ... | ... |
test/routing_test.rb
... | ... | @@ -20,4 +20,13 @@ class RoutingTest < Minitest::Test |
20 | 20 | store_names ["Dollar Tree"], Store |
21 | 21 | assert_search "*", ["Dollar Tree"], {routing: "Boom"}, Store |
22 | 22 | end |
23 | + | |
24 | + def test_routing_async | |
25 | + skip unless defined?(ActiveJob) | |
26 | + | |
27 | + with_options(Song, routing: true, callbacks: :async) do | |
28 | + store_names ["Dollar Tree"], Song | |
29 | + Song.destroy_all | |
30 | + end | |
31 | + end | |
23 | 32 | end | ... | ... |