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

Upgrade to Algolia client v2 #244

Closed
wants to merge 1 commit into from

Conversation

julienbourdeau
Copy link
Contributor

Q A
Bug fix? no
New feature? no
BC breaks? I don't think so, but need further investigation
Need Doc update not sure, maybe about service declaration and installing Guzzle

What was changed

Update to version Version 2 of the API client. The version isn't out yet, this PR is here to check how hard it is.

See more details on discourse: https://discourse.algolia.com/t/introducing-php-api-client-v2/5635

@@ -15,7 +15,7 @@ public function update($searchableEntities)
$batch = $this->doUpdate($searchableEntities);

foreach ($batch as $indexName => $response) {
$this->algolia->initIndex($indexName)->waitTask($response['taskID']);
$this->algolia->waitTask($indexName, $response['taskID']);
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the rationale of not using $this->algolia->index($indexName)->waitTask($response['taskID']). It feels weird to have this waitTask method taking the index name as 1st parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We recently exposed waitTask in the client for 2 main reasons:

  1. To make it easier to work with multiple index endpoint (which are on the client)
  2. To make it easier to work with other API, like analytics that returns a index name and a task ID.

More details: algolia/algoliasearch-client-php#410

I thought it would best to avoid instanciating an index "just" for a waitTask but I didn't benchmark anything, I guess the performance gain would be negligable. It just felt easier.

Note that internally, Client::waitTask will instanciate an Index until we find a better solution to not duplicate the wait logic, which I don't think is possible with PHP 5.3 because:

  • Traits are not available (introduce in 5.4)
  • this is not available in closures (introduce in 5.4)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And thanks for taking the time to review 🙏 Feedback is greatly appreciated!

@@ -15,7 +14,9 @@ public function boot()
{
parent::boot();

Version::addSuffixUserAgentSegment('Symfony Search Bundle', self::VERSION);
Version::addSuffixUserAgentSegment('Symfony', SfKernel::VERSION);
if (class_exists('Algolia\AlgoliaSearch\Support\Config')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what the PHP requirement of this package is (there's none in composer.json which is bad enough), but starting with 5.5.0 there's the ::class constant that you should use instead of magic strings. This allows IDEs to find code like this when looking for usages of a class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't specify it because I'm maintaining the same as Symfony 3.4, which requires ^5.5.9. I will update the PR. For the client, I'm maintaing 5.3 so I sort of lost the habit of ::class ^^

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense. I would still recommend applying the PHP requirement explicitly in composer.json to be on the safe side to avoid relying on other libraries' constraints.

<argument key="$applicationID">%env(ALGOLIA_APP_ID)%</argument>
<service id="algolia_client" class="Algolia\AlgoliaSearch\Client" public="false">
<factory class="Algolia\AlgoliaSearch\Client" method="create"/>
<argument key="$appId ">%env(ALGOLIA_APP_ID)%</argument>
Copy link
Contributor

Choose a reason for hiding this comment

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

There are extra spaces behind the key here.

@kiler129
Copy link
Contributor

kiler129 commented Mar 7, 2019

@julienbourdeau: Are you maybe willing to rebase this and finish fully? The 1.x has a "slight" performance problem:

image

Edit

After some testing it looks like calling the curl_multi_select without timeout is hitting the performance REALLY hard. The screenshot below shows comparison with the current code executed via v1 SDK vs. removing 0.1 timeout from curl_multi_select:

image

@nunomaduro I think upgrading to v2 SDK should be prioritized. If not maybe we can add an option to v1 SDK (even if EOL now) to let user specify the timeout with default value of 0.1s so no BC is kept?
In the current state searching from PHP is quite unusable if so slow :(

@ericabouaf
Copy link

Having the same issue as @kiler129 ...

@julienbourdeau : Any update on this one ?

@nunomaduro
Copy link
Contributor

@neyric Thanks for asking, we are going to develop algolia/search-bundle v4 next quarter. It should be out months before the end of the year. 👍

@chloelbn
Copy link
Contributor

I'm closing this issue due to a lack of activity. I will take this pull request in consideration once I start work on the migration of the api client

@chloelbn chloelbn closed this Sep 11, 2019
@chloelbn chloelbn deleted the update/algolia-client-v2 branch November 26, 2020 10:24
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.

8 participants