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

Typesense driver makes unnecessary api cals #818

Closed
ingria opened this issue Apr 6, 2024 · 3 comments
Closed

Typesense driver makes unnecessary api cals #818

ingria opened this issue Apr 6, 2024 · 3 comments

Comments

@ingria
Copy link

ingria commented Apr 6, 2024

Scout Version

10.8.5

Scout Driver

Typesense

Laravel Version

10

PHP Version

8.3.3

Database Driver & Version

No response

SDK Version

No response

Meilisearch CLI Version

No response

Description

At the moment, typesence-driver makes two http requests on any model update, even if the changed field is not in the document schema. This causes performance problems if there are a lot of updates.

Real life example: I have a collection with over 10000 documents in it. Each document is updated hourly. Each update changes one model attribute, which triggers 2 request to typesense server. That's 5.5 completely unnecessary requests per second.

This issue has been fixed in Typesense official driver (typesense/laravel-scout-typesense-driver#23), but not in Laravel official driver.

Steps To Reproduce

  1. Create a model with two attributes:
// MyModel.php
public function toSearchableArray(): array {
    return [
        'id' => (string) $this->id,
        'name' => $this->name,
    ];
}

// config/scout.php
[
  'typesense' => [
    'model-settings' => [
      'App\Models\MyModel' => [
        'collection-schema' => [
          'name' => 'my-model',
          'fields' => [
            [
              'name' => 'id',
              'type' => 'string',
            ],
            [
              'name' => 'name',
              'type' => 'string',
            ],
          ],
        ],
      ],
    ],
  ],
];
  1. Update any non-existent attribute:
MyModel::first()->update([
    'some_field' => 'test',
]);

// scout sends GET to /collections/my-model
// scout sends POST to /collections/my-model/documents/import

MyModel::first()->update([
    'some_date' => now(),
]);

// scout sends GET to /collections/my-model
// scout sends POST to /collections/my-model/documents/import
@AbdullahFaqeir
Copy link
Contributor

Hey @ingria,

I'll make sure to submit a PR to fix this in the scout official driver.

CC : @jasonbosco

Copy link

github-actions bot commented Apr 8, 2024

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

taylorotwell pushed a commit that referenced this issue Apr 9, 2024
* - Prevent unnecessary api calls on Collection (index).

* - style fix.

* - Added Typesense searchable test case.
@AbdullahFaqeir
Copy link
Contributor

Fixed with #820, should be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants