Skip to content
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:settings changes detection issue with empty array #424

Conversation

kiyohara
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? no
Related Issue -
Need Doc update no

Describe your change

If you set customRanking as an empty Array, like below, Algolia understands that you set the customRanking as null.

class Product < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch do
    customRanking [] # emptry Array
  end
end

As a result, the index setting API ( /1/indexes/%s/settings?getVersion=1 ) returns setting information like below.
customRanking is nil.

=> {
 "minWordSizefor1Typo"=>4,
 "minWordSizefor2Typos"=>8,
 "hitsPerPage"=>20,
 "maxValuesPerFacet"=>100,
 "version"=>1,
 # snip
 "customRanking"=>nil # API's response, raw JSON, is "customRanking":null
}

This behavior is natural and understandable.
However, the settings changes checking function does not handle this difference correctly.
So, I add an additional compare logic to the function, especially [] and nil comparing using blank? method.

What problem is this fixing?

If you set customRanking ( or any other attributes ) as an empty Array , a useless index setting update API will be called when you use the search function.
It's heavy and blocking(synchronous) API calling, so your search function might be timed out.

@kiyohara
Copy link
Contributor Author

Any specs error has been occurred caused by Invalid Application-ID or API key (Algolia::AlgoliaHttpError).
I guess it's a permission issue I can't solve.
Is there anything I can do?

Copy link
Contributor

@DevinCodes DevinCodes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR @kiyohara ! 🙇‍♂️

The CI is failing because environment variables aren't available in our CI when ran from a fork. I've restarted it so that the credentials get loaded, it's looking good! 🙂

@DevinCodes DevinCodes merged commit 0ad3450 into algolia:master Apr 8, 2022
@kiyohara kiyohara deleted the fix/settings_changes_detection_issue_with_empty_array branch April 11, 2022 03:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants