Skip to content

Commit c7654a9

Browse files
committed
Revert to creating index asynchronously
Creating the index synchronously was required to get an up to version of its settings, in order to compare them to the user configuration and decide whether or not to update settings. Unfortunately this made practically every operation have a synchronous component causing a lot of problems down the line. This commit reverts to using create_index asynchronously to avoid said issues, and represents the settings of a nonexistent index as an empty hash, which will queue an update_settings if the user has specified any settings at all.
1 parent 29f59c8 commit c7654a9

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

lib/meilisearch-rails.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def initialize(index_uid, raise_on_failure, options)
261261
@raise_on_failure = raise_on_failure.nil? || raise_on_failure
262262

263263
SafeIndex.log_or_throw(nil, @raise_on_failure) do
264-
client.create_index!(index_uid, { primary_key: primary_key })
264+
client.create_index(index_uid, { primary_key: primary_key })
265265
end
266266

267267
@index = client.index(index_uid)
@@ -306,7 +306,7 @@ def settings(*args)
306306
SafeIndex.log_or_throw(:settings, @raise_on_failure) do
307307
@index.settings(*args)
308308
rescue ::MeiliSearch::ApiError => e
309-
return {} if e.code == 404 # not fatal
309+
return {} if e.code == 'index_not_found' # not fatal
310310

311311
raise e
312312
end

spec/integration_spec.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,23 +1136,22 @@
11361136
let(:index_instance) { instance_double(MeiliSearch::Index, settings: nil, update_settings: nil) }
11371137
let(:slow_client) { instance_double(MeiliSearch::Client, index: index_instance) }
11381138

1139+
before do
1140+
allow(slow_client).to receive(:create_index)
1141+
allow(MeiliSearch::Rails).to receive(:client).and_return(slow_client)
1142+
end
1143+
11391144
it 'does not raise error timeouts on reindex' do
11401145
allow(index_instance).to receive(:add_documents).and_raise(MeiliSearch::TimeoutError)
1141-
allow(slow_client).to receive(:create_index!).and_return(index_instance)
1142-
1143-
allow(MeiliSearch::Rails).to receive(:client).and_return(slow_client)
11441146

11451147
expect do
11461148
Vegetable.create(name: 'potato')
11471149
end.not_to raise_error
11481150
end
11491151

11501152
it 'does not raise error timeouts on data addition' do
1151-
allow(slow_client).to receive(:create_index!).and_raise(MeiliSearch::TimeoutError)
11521153
allow(index_instance).to receive(:add_documents).and_return(nil)
11531154

1154-
allow(MeiliSearch::Rails).to receive(:client).and_return(slow_client)
1155-
11561155
expect do
11571156
Vegetable.ms_reindex!
11581157
end.not_to raise_error

0 commit comments

Comments
 (0)