-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: make sync opt to be selectable for auto setting update logic #425
fix: make sync opt to be selectable for auto setting update logic #425
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @kiyohara !
Thank you again for your contribution. I think it's a very valid one, so I'd love to merge this. Before we merge it, though, could you please write a test to ensure it works properly?
Thank you in advance!
(Don't worry about the failing CI for now, this is due to credentials as mentioned in another of your PRs 😉 )
Hi @DevinCodes. Thank you for your review. Of course, All tests I added have passed in my local dev env. I'll also add the tests for another PR #426 soon. |
…o_setting_update_logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just have one small suggestion, other than that this looks good! Let me know what you think 🙂
spec/integration_spec.rb
Outdated
end | ||
|
||
it 'should not call set_setting!' do | ||
expect_any_instance_of(Algolia::Search::Index).not_to receive(:set_settings) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be as follows?
expect_any_instance_of(Algolia::Search::Index).not_to receive(:set_settings) | |
expect_any_instance_of(Algolia::Search::Index).not_to receive(:set_settings!) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your suggestion is perfectly right.
On the other hand, I was wondering why this test passed.
After additional investigation, it turns out that I have overlooked the cache mechanism.
When algolia_ensure_init
is called more than once, neither set_settings
nor set_settings!
were being called ever at the second time and after, under any conditions.
I should have used the Red-Green-Refactor approach, but I skipped the Red check phase. embarrassing.
I have fixed the test, please check it out.
…ate_logic' of github.com:kiyohara/algoliasearch-rails into fix/make_sync_opt_to_be_selectable_for_auto_setting_update_logic
@DevinCodes I believe the test is more complete thanks to your suggestions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you again @kiyohara ! 🙇♂️
The PR looks great, I just have one question. This is probably to some context that I'm missing, but afterwards we can merge the PR I think 😄
spec/integration_spec.rb
Outdated
end | ||
|
||
it 'should call set_setting' do # NOTE: set_setting! call set_setting internally. | ||
expect_any_instance_of(Algolia::Search::Index).to receive(:set_settings).and_call_original |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand why we need to add the .and_call_original
at the end here. Could you explain why this is needed, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a very good point.
Initially, I was going to write a test here to make sure that set_setting
is not executed as opposed to the above test to make sure that set_setting!
is executed.
However, I found that set_setting!
executes set_setting
internally, so I changed it to a test to make sure that set_setting
is executed.
set_setting!
use the return value of set_setting
, so and_call_original
was needed.
However, your point has made me realize that.
If set_setting!
is using set_setting
internally, then there is no point in testing the contrast between the two.
I think the key point is whether it is asynchronous, i.e., whether the wait_task
is executed.
I modified the test according to this concept.
May I ask you to check it again, please?
spec/integration_spec.rb
Outdated
end | ||
|
||
it 'should call set_setting' do | ||
expect_any_instance_of(Algolia::Search::Index).to receive(:set_settings).and_call_original |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unlike the previous line, this line is a simple typo.
cand_call_original
was not needed. 🙇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @kiyohara ! 🚀
I'm so happy! 😄 |
@DevinCodes I'm so happy that this PR was merged. Thank you so much. Half of the several problems with our web service operations have been resolved with the new release of algoliasearch-client-ruby. We are so glad and appreciate you 🙏 We are eagerly waiting for the other half of the issues to be resolved by a new version releasing of algoliasearch-rails 😄 |
Thank you for the follow-up @kiyohara , and sorry for the delay! We'll release a new version on Monday. Your changes will be included in that release 🙂 |
@DevinCodes Sorry for urging you to release a new version. I appreciate your kindness. |
@kiyohara we've just released v2.2.1 with your changes. Thank you again for your contributions 🙂 |
@DevinCodes I'm so glad! 🎉 Thank you for your arrangement of the release 🙏 |
Describe your change
In algoliasearch-rails gem 1.x the auto setting update logic run asynchronously.
This behavior has been changed since the version 2.0 release to 'synchronously API call.'
ref. Here is the discussion that considered changing the specification.
It means if you have some settings changes, all API calls hook the setting update API, and are blocked until the settings changing process is finished in Algolia server.
I believe the spec change is reasonable for almost all situations because in many cases API calls require the response based on the new setting immediately.
However, I think, Algolia is a backend for sites that has big records and big client accesses, and is required quick response without '504 Gateway Timeout'.
I guess this is one of the reasons that all methods' default sync option is set as 'asynchronous' in this gem, like the algolia_set_settings method.
I think the best way how to decide the sync behavior, especially focused on "auto setting update logic", is to depend on
AlgoliaSearch.configuration
's:synchronous
option similar to any other method's default option like this.This PR add sync option select logic in auto setting update func.
It decide a sync option (sync or async) based on the above config.
The default behavior is async, same as 1.x.
What problem is this fixing?
When you deploy some new index settings changes to your site using this gem, your site clients might see '504 Gateway Timeout' when they search anything.
This is a real problem we are experiencing with our site management.
Many 504 responses are occurred when we update index settings.
We believe that a quick response with a little incorrect is better than a slow response that is 100% correct (and sometimes it's 504), for our site customers.
So, we decided to change back gem version to 1.26.0.
Of cause, I understand that it's not all user's requirements.
So, I fix it to depend on
AlgoliaSearch.configuration
.