Commit fce3f92e2fc9ea8bf7cfab0efbde58d789b9052d
1 parent
7bc3d4b7
Exists in
master
and in
2 other branches
Moved ReindexV2Job to BulkRecordIndexer [skip ci]
Showing
3 changed files
with
11 additions
and
27 deletions
Show diff stats
lib/searchkick/bulk_record_indexer.rb
@@ -31,12 +31,12 @@ module Searchkick | @@ -31,12 +31,12 @@ module Searchkick | ||
31 | end | 31 | end |
32 | end | 32 | end |
33 | 33 | ||
34 | - def reindex_items(klass, items) | 34 | + def reindex_items(klass, items, method_name:) |
35 | routing = items.to_h { |r| [r[:id], r[:routing]] } | 35 | routing = items.to_h { |r| [r[:id], r[:routing]] } |
36 | record_ids = routing.keys | 36 | record_ids = routing.keys |
37 | 37 | ||
38 | scope = Searchkick.load_records(klass, record_ids) | 38 | scope = Searchkick.load_records(klass, record_ids) |
39 | - scope = scope.search_import if scope.respond_to?(:search_import) | 39 | + # scope = scope.search_import if scope.respond_to?(:search_import) |
40 | records = scope.select(&:should_index?) | 40 | records = scope.select(&:should_index?) |
41 | 41 | ||
42 | # determine which records to delete | 42 | # determine which records to delete |
@@ -46,7 +46,7 @@ module Searchkick | @@ -46,7 +46,7 @@ module Searchkick | ||
46 | construct_record(klass, id, routing[id]) | 46 | construct_record(klass, id, routing[id]) |
47 | end | 47 | end |
48 | 48 | ||
49 | - import_inline(records, delete_records, method_name: nil) | 49 | + import_inline(records, delete_records, method_name: method_name) |
50 | end | 50 | end |
51 | 51 | ||
52 | private | 52 | private |
lib/searchkick/process_batch_job.rb
@@ -13,7 +13,9 @@ module Searchkick | @@ -13,7 +13,9 @@ module Searchkick | ||
13 | {id: parts[0], routing: parts[1]} | 13 | {id: parts[0], routing: parts[1]} |
14 | end | 14 | end |
15 | 15 | ||
16 | - index.send(:bulk_record_indexer).reindex_items(klass, items) | 16 | + relation = klass |
17 | + relation = relation.search_import if relation.respond_to?(:search_import) | ||
18 | + index.send(:bulk_record_indexer).reindex_items(relation, items, method_name: nil) | ||
17 | end | 19 | end |
18 | end | 20 | end |
19 | end | 21 | end |
lib/searchkick/reindex_v2_job.rb
1 | module Searchkick | 1 | module Searchkick |
2 | class ReindexV2Job < ActiveJob::Base | 2 | class ReindexV2Job < ActiveJob::Base |
3 | - RECORD_NOT_FOUND_CLASSES = [ | ||
4 | - "ActiveRecord::RecordNotFound", | ||
5 | - "Mongoid::Errors::DocumentNotFound" | ||
6 | - ] | ||
7 | - | ||
8 | queue_as { Searchkick.queue_name } | 3 | queue_as { Searchkick.queue_name } |
9 | 4 | ||
10 | def perform(klass, id, method_name = nil, routing: nil) | 5 | def perform(klass, id, method_name = nil, routing: nil) |
11 | model = klass.constantize | 6 | model = klass.constantize |
12 | - record = | ||
13 | - begin | ||
14 | - if model.respond_to?(:unscoped) | ||
15 | - model.unscoped.find(id) | ||
16 | - else | ||
17 | - model.find(id) | ||
18 | - end | ||
19 | - rescue => e | ||
20 | - # check by name rather than rescue directly so we don't need | ||
21 | - # to determine which classes are defined | ||
22 | - raise e unless RECORD_NOT_FOUND_CLASSES.include?(e.class.name) | ||
23 | - nil | ||
24 | - end | ||
25 | - | ||
26 | - # TODO move construct_record logic | ||
27 | - record ||= model.searchkick_index.send(:bulk_record_indexer).send(:construct_record, model, id, routing) | ||
28 | - | ||
29 | - RecordIndexer.new(record).reindex(method_name, mode: :inline) | 7 | + # may not be needed if calling search_import later |
8 | + model = model.unscoped if model.respond_to?(:unscoped) | ||
9 | + items = [{id: id, routing: routing}] | ||
10 | + # TODO improve notification | ||
11 | + model.searchkick_index.send(:bulk_record_indexer).reindex_items(model, items, method_name: method_name) | ||
30 | end | 12 | end |
31 | end | 13 | end |
32 | end | 14 | end |