Commit 9559e3f8f046c23c25a28a18b320e3bde4ab1271
1 parent
e5550dd2
Exists in
reindex_refactor
Bulk indexer [skip ci]
Showing
1 changed file
with
11 additions
and
15 deletions
Show diff stats
lib/searchkick/record_indexer.rb
... | ... | @@ -60,22 +60,18 @@ module Searchkick |
60 | 60 | |
61 | 61 | delete_records, index_records = records.partition { |r| r.destroyed? || !r.persisted? || !r.should_index? } |
62 | 62 | |
63 | - # TODO use | |
64 | - # Searchkick.callbacks(:bulk) | |
65 | - # and | |
66 | - # index.bulk_delete(delete_records) | |
67 | - delete_records.each do |record| | |
68 | - begin | |
69 | - index.remove(record) | |
70 | - rescue Elasticsearch::Transport::Transport::Errors::NotFound | |
71 | - # do nothing | |
63 | + Searchkick.callbacks(:bulk) do | |
64 | + if index_records.any? | |
65 | + if method_name | |
66 | + index.bulk_update(index_records, method_name) | |
67 | + else | |
68 | + index.bulk_index(index_records) | |
69 | + end | |
70 | + end | |
71 | + if delete_records.any? | |
72 | + # TODO rescue not found errors? | |
73 | + index.bulk_delete(delete_records) | |
72 | 74 | end |
73 | - end | |
74 | - | |
75 | - if method_name | |
76 | - index.bulk_update(index_records, method_name) | |
77 | - else | |
78 | - index.bulk_index(index_records) | |
79 | 75 | end |
80 | 76 | |
81 | 77 | index.refresh if refresh | ... | ... |