From 1c35e45886369d8c28f6ef3e819e34c337259c23 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Sun, 20 Feb 2022 23:43:25 -0800 Subject: [PATCH] Added index_name to ReindexV2Job [skip ci] --- lib/searchkick/record_indexer.rb | 6 ++++-- lib/searchkick/reindex_v2_job.rb | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/searchkick/record_indexer.rb b/lib/searchkick/record_indexer.rb index 391480a..234ca4d 100644 --- a/lib/searchkick/record_indexer.rb +++ b/lib/searchkick/record_indexer.rb @@ -17,7 +17,8 @@ module Searchkick raise Searchkick::Error, "Active Job not found" end - # temporary hack + # we could likely combine ReindexV2Job, BulkReindexJob, and ProcessBatchJob + # but keep them separate for now if single record = records.first @@ -31,7 +32,8 @@ module Searchkick record.class.name, record.id.to_s, method_name ? method_name.to_s : nil, - routing: routing + routing: routing, + index_name: index.name ) else Searchkick::BulkReindexJob.perform_later( diff --git a/lib/searchkick/reindex_v2_job.rb b/lib/searchkick/reindex_v2_job.rb index 5bbe9e7..d5308d2 100644 --- a/lib/searchkick/reindex_v2_job.rb +++ b/lib/searchkick/reindex_v2_job.rb @@ -2,15 +2,16 @@ module Searchkick class ReindexV2Job < ActiveJob::Base queue_as { Searchkick.queue_name } - def perform(class_name, id, method_name = nil, routing: nil) + def perform(class_name, id, method_name = nil, routing: nil, index_name: nil) model = Searchkick.load_model(class_name, allow_child: true) + index = index_name ? Searchkick::Index.new(index_name, model.searchkick_options) : model.searchkick_index # use should_index? to decide whether to index (not default scope) # just like saving inline # could use Searchkick.scope() in future # but keep for now for backwards compatibility model = model.unscoped if model.respond_to?(:unscoped) items = [{id: id, routing: routing}] - model.searchkick_index.send(:record_indexer).reindex_items(model, items, method_name: method_name, single: true) + index.send(:record_indexer).reindex_items(model, items, method_name: method_name, single: true) end end end -- libgit2 0.21.0