From 03e0107dd00e0bc152a9162799cdf21fec1b7b3a Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Thu, 24 Feb 2022 06:36:20 -0800 Subject: [PATCH] Prefer mode: :async over async: true for full reindex --- CHANGELOG.md | 4 ++++ lib/searchkick/index.rb | 25 ++++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 340e084..99419a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.0.1 (unreleased) + +- Prefer `mode: :async` over `async: true` for full reindex + ## 5.0.0 (2022-02-21) - Searches now use lazy loading (similar to Active Record) diff --git a/lib/searchkick/index.rb b/lib/searchkick/index.rb index 25d811b..4d2d942 100644 --- a/lib/searchkick/index.rb +++ b/lib/searchkick/index.rb @@ -237,6 +237,19 @@ module Searchkick self.refresh if refresh true else + async = options.delete(:async) + if async + if async.is_a?(Hash) && async[:wait] + # TODO warn in 5.1 + # Searchkick.warn "async option is deprecated - use mode: :async, wait: true instead" + options[:wait] = true unless options.key?(:wait) + else + # TODO warn in 5.1 + # Searchkick.warn "async option is deprecated - use mode: :async instead" + end + options[:mode] ||= :async + end + full_reindex(relation, **options) end end @@ -337,7 +350,9 @@ module Searchkick # https://gist.github.com/jarosan/3124884 # http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/ # TODO deprecate async in favor of mode: :async, wait: true/false - def full_reindex(relation, import: true, resume: false, retain: false, async: false, refresh_interval: nil, scope: nil) + def full_reindex(relation, import: true, resume: false, retain: false, mode: nil, refresh_interval: nil, scope: nil, wait: nil) + raise ArgumentError, "wait only available in :async mode" if !wait.nil? && mode != :async + if resume index_name = all_indices.sort.last raise Searchkick::Error, "No index to resume" unless index_name @@ -351,7 +366,7 @@ module Searchkick end import_options = { - mode: (async ? :async : :inline), + mode: mode, full: true, resume: resume, scope: scope @@ -365,7 +380,7 @@ module Searchkick import_before_promotion(index, relation, **import_options) if import # get existing indices to remove - unless async + unless mode == :async check_uuid(uuid, index.uuid) promote(index.name, update_refresh_interval: !refresh_interval.nil?) clean_indices unless retain @@ -378,8 +393,8 @@ module Searchkick index.import_scope(relation, **import_options) if import end - if async - if async.is_a?(Hash) && async[:wait] + if mode == :async + if wait puts "Created index: #{index.name}" puts "Jobs queued. Waiting..." loop do -- libgit2 0.21.0