Commit bb8854d19294ce18634eaa26188db7697ee93722

Authored by Andrew Kane
1 parent 80457def

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 16 relation = relation.search_import
17 17 end
18 18  
19   - # remove unneeded conditions for async
  19 + # remove unneeded loading for async
20 20 if mode == :async
21 21 if relation.respond_to?(:primary_key)
22 22 relation = relation.select(relation.primary_key).except(:includes, :preload)
... ... @@ -72,6 +72,7 @@ module Searchkick
72 72  
73 73 def full_reindex_async(relation)
74 74 batch_id = 1
  75 + class_name = relation.searchkick_options[:class_name]
75 76  
76 77 if relation.respond_to?(:primary_key)
77 78 # TODO expire Redis key
... ... @@ -92,18 +93,18 @@ module Searchkick
92 93  
93 94 batches_count.times do |i|
94 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 97 batch_id += 1
97 98 end
98 99 else
99 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 102 batch_id += 1
102 103 end
103 104 end
104 105 else
105 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 108 batch_id += 1
108 109 end
109 110 end
... ... @@ -123,10 +124,10 @@ module Searchkick
123 124 yield items if items.any?
124 125 end
125 126  
126   - def bulk_reindex_job(relation, batch_id, **options)
  127 + def batch_job(class_name, batch_id, **options)
127 128 Searchkick.with_redis { |r| r.sadd(batches_key, batch_id) }
128 129 Searchkick::BulkReindexJob.perform_later(
129   - class_name: relation.searchkick_options[:class_name],
  130 + class_name: class_name,
130 131 index_name: index.name,
131 132 batch_id: batch_id,
132 133 **options
... ...