Skip to content

Commit

Permalink
Added warning for full reindex and :queue mode - closes #1658
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jun 16, 2024
1 parent 6e1fbc6 commit 528f506
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 5.4.0 (unreleased)

- Added warning for full reindex and `:queue` mode

## 5.3.1 (2023-11-28)

- Fixed error with misspellings below and failed queries
Expand Down
2 changes: 2 additions & 0 deletions lib/searchkick/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ def reindex_records(object, mode: nil, refresh: false, **options)
# http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/
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
# TODO raise ArgumentError in Searchkick 6
Searchkick.warn("Full reindex does not support :queue mode - use :async mode instead") if mode == :queue

if resume
index_name = all_indices.sort.last
Expand Down
24 changes: 24 additions & 0 deletions test/reindex_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,24 @@ def test_relation_queue
assert_search "product", ["Product A", "Product B"]
end

def test_relation_queue_all
reindex_queue = Product.searchkick_index.reindex_queue
reindex_queue.clear

store_names ["Product A"]
store_names ["Product B", "Product C"], reindex: false

Product.all.reindex(mode: :queue)
Product.searchkick_index.refresh
assert_search "product", ["Product A"]

perform_enqueued_jobs do
Searchkick::ProcessQueueJob.perform_now(class_name: "Product")
end
Product.searchkick_index.refresh
assert_search "product", ["Product A", "Product B", "Product C"]
end

def test_relation_queue_routing
reindex_queue = Store.searchkick_index.reindex_queue
reindex_queue.clear
Expand Down Expand Up @@ -243,6 +261,12 @@ def test_full_async_non_integer_pk
Sku.destroy_all
end

def test_full_queue
assert_warns "Full reindex does not support :queue mode - use :async mode instead" do
Product.reindex(mode: :queue)
end
end

def test_full_refresh_interval
reindex = Product.reindex(refresh_interval: "30s", mode: :async, import: false)
index = Searchkick::Index.new(reindex[:index_name])
Expand Down

0 comments on commit 528f506

Please sign in to comment.