-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
301: Correctly check if index settings have been updated r=brunoocasali a=ellnix # Pull Request ## Related issue Fixes #280 (partly) - In issue #280 there is also the related problem of a redundant request to create an already existing index the first time it is used. However this request should not be significant to performance, so we can deal with it in a better way after some refactoring. ## PR checklist Please check if your PR fulfills the following requirements: - [X] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [X] Have you read the contributing guidelines? - [X] Have you made sure that the title is accurate and descriptive of the changes? # Notes (please read) I believe this fixes issue #280 (I could not reproduce it after this edit). I will add regression tests when I have the time (it took a while trying to figure out what was going wrong). The problem was (to the extent I have determined it): - The first time an index is used `ms_ensure_init` will fetch it from the MeiliSearch instance - Subsequent calls for that same index will have been memoized, so this problem occurs only once (makes it harder to test), however in background jobs this memoization is not relevant - During that first call when the index is first fetched from the MeiliSearch instance, its settings are checked with the current settings to see if they need updating, from here there are 2 separate issues: 1. The previous settings are not fetched correctly: [this line](https://github.com/meilisearch/meilisearch-rails/blob/e7a12569f18ee40684c3c643a3cf573f3465c62e/lib/meilisearch-rails.rb#L744C37-L744C37) provides an argument to `MeiliSearch::Client#settings` which takes no arguments and therefore causes an `ArgumentError` which is then rescued with nil (moral of the story always specify the exception you are `rescue`-ing) ```ruby current_settings = `@ms_indexes[MeiliSearch::Rails.active?][settings].settings(getVersion:` 1) rescue nil ``` 2. The [`meilisearch_settings_changed?`](https://github.com/meilisearch/meilisearch-rails/blob/e7a12569f18ee40684c3c643a3cf573f3465c62e/lib/meilisearch-rails.rb#L797) method has therefore never been run up to this point (as far as I can see) and has several problems that have therefore never been addressed 1. The `prev` keys are not just strings instead of symbols, they are also camelCase-d 2. There is no guaranteed order to `current` and `prev` values if they are arrays, and `==` comparison between Arrays will be false if their elements have different orders Co-authored-by: ellnix <[email protected]>
- Loading branch information
Showing
4 changed files
with
96 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'spec_helper' | ||
|
||
describe MeiliSearch::Rails::IndexSettings do | ||
describe 'settings change detection' do | ||
let(:record) { Color.create name: 'dark-blue', short_name: 'blue' } | ||
|
||
context 'without changing settings' do | ||
it 'does not call update settings' do | ||
allow(Color.index).to receive(:update_settings).and_call_original | ||
|
||
record.ms_index! | ||
|
||
expect(Color.index).not_to have_received(:update_settings) | ||
end | ||
end | ||
|
||
context 'when settings have been changed' do | ||
it 'makes a request to update settings' do | ||
idx = Color.index | ||
task = idx.update_settings( | ||
filterable_attributes: ['none'] | ||
) | ||
idx.wait_for_task task['taskUid'] | ||
|
||
allow(idx).to receive(:update_settings).and_call_original | ||
|
||
record.ms_index! | ||
|
||
expect(Color.index).to have_received(:update_settings).once | ||
end | ||
end | ||
end | ||
end |