Commit bb8854d19294ce18634eaa26188db7697ee93722
1 parent
80457def
Exists in
master
and in
2 other branches
Improved naming and code [skip ci]
Showing
1 changed file
with
7 additions
and
6 deletions
Show diff stats
lib/searchkick/relation_indexer.rb
@@ -16,7 +16,7 @@ module Searchkick | @@ -16,7 +16,7 @@ module Searchkick | ||
16 | relation = relation.search_import | 16 | relation = relation.search_import |
17 | end | 17 | end |
18 | 18 | ||
19 | - # remove unneeded conditions for async | 19 | + # remove unneeded loading for async |
20 | if mode == :async | 20 | if mode == :async |
21 | if relation.respond_to?(:primary_key) | 21 | if relation.respond_to?(:primary_key) |
22 | relation = relation.select(relation.primary_key).except(:includes, :preload) | 22 | relation = relation.select(relation.primary_key).except(:includes, :preload) |
@@ -72,6 +72,7 @@ module Searchkick | @@ -72,6 +72,7 @@ module Searchkick | ||
72 | 72 | ||
73 | def full_reindex_async(relation) | 73 | def full_reindex_async(relation) |
74 | batch_id = 1 | 74 | batch_id = 1 |
75 | + class_name = relation.searchkick_options[:class_name] | ||
75 | 76 | ||
76 | if relation.respond_to?(:primary_key) | 77 | if relation.respond_to?(:primary_key) |
77 | # TODO expire Redis key | 78 | # TODO expire Redis key |
@@ -92,18 +93,18 @@ module Searchkick | @@ -92,18 +93,18 @@ module Searchkick | ||
92 | 93 | ||
93 | batches_count.times do |i| | 94 | batches_count.times do |i| |
94 | min_id = starting_id + (i * batch_size) | 95 | min_id = starting_id + (i * batch_size) |
95 | - bulk_reindex_job(relation, batch_id, min_id: min_id, max_id: min_id + batch_size - 1) | 96 | + batch_job(class_name, batch_id, min_id: min_id, max_id: min_id + batch_size - 1) |
96 | batch_id += 1 | 97 | batch_id += 1 |
97 | end | 98 | end |
98 | else | 99 | else |
99 | relation.find_in_batches(batch_size: batch_size) do |batch| | 100 | relation.find_in_batches(batch_size: batch_size) do |batch| |
100 | - bulk_reindex_job(relation, batch_id, record_ids: batch.map { |record| record.id.to_s }) | 101 | + batch_job(class_name, batch_id, record_ids: batch.map { |record| record.id.to_s }) |
101 | batch_id += 1 | 102 | batch_id += 1 |
102 | end | 103 | end |
103 | end | 104 | end |
104 | else | 105 | else |
105 | each_batch(relation, batch_size: batch_size) do |items| | 106 | each_batch(relation, batch_size: batch_size) do |items| |
106 | - bulk_reindex_job(relation, batch_id, record_ids: items.map { |i| i.id.to_s }) | 107 | + batch_job(class_name, batch_id, record_ids: items.map { |i| i.id.to_s }) |
107 | batch_id += 1 | 108 | batch_id += 1 |
108 | end | 109 | end |
109 | end | 110 | end |
@@ -123,10 +124,10 @@ module Searchkick | @@ -123,10 +124,10 @@ module Searchkick | ||
123 | yield items if items.any? | 124 | yield items if items.any? |
124 | end | 125 | end |
125 | 126 | ||
126 | - def bulk_reindex_job(relation, batch_id, **options) | 127 | + def batch_job(class_name, batch_id, **options) |
127 | Searchkick.with_redis { |r| r.sadd(batches_key, batch_id) } | 128 | Searchkick.with_redis { |r| r.sadd(batches_key, batch_id) } |
128 | Searchkick::BulkReindexJob.perform_later( | 129 | Searchkick::BulkReindexJob.perform_later( |
129 | - class_name: relation.searchkick_options[:class_name], | 130 | + class_name: class_name, |
130 | index_name: index.name, | 131 | index_name: index.name, |
131 | batch_id: batch_id, | 132 | batch_id: batch_id, |
132 | **options | 133 | **options |