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

shouldBeSearchable is not called during processing of MakeSearchable with SCOUT_QUEUE=true #756

Closed
oprypkhantc opened this issue Aug 18, 2023 · 2 comments

Comments

@oprypkhantc
Copy link

Scout Version

10.2.4

Scout Driver

Algolia

Laravel Version

10.19.0

PHP Version

8.1.21

Database Driver & Version

No response

SDK Version

Other (ElasticSearch)

Meilisearch CLI Version

No response

Description

Hey.

Scout allows specifying shouldBeSearchable method that checks whether a given model should even indexed into search. With SCOUT_QUEUE=false it works as expected: if shouldBeSearchable returns true, then that same model instance is synchronously converted to array with toSearchableArray and sent to a search driver.

With SCOUT_QUEUE=true it doesn't quite work as expected: if shouldBeSearchable initially returns true, then that model ID is sent to queue. A queue worker then pulls that item from the database and shouldBeSearchable might now return false if said item changed in between dispatching the job and it actually being processed. This, in turn, may lead to toSearchableArray throwing an error.

It might be a good idea to also be checking shouldBeSearchable inside the MakeSearchable job, after the models have been fetched from the database, to make sure that the job is still relevant.

Steps To Reproduce

  1. Set SCOUT_QUEUE=true
  2. Do ->searchable() on a model that has shouldBeSearchable() returning true
  3. Change the shouldBeSearchable() to be returning false
  4. Start the queue worker, see that toSearchableArray() was called even though shouldBeSearchable() is now returning false
@github-actions
Copy link

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!

@driesvints
Copy link
Member

Closing this issue because it's inactive, already solved, old or not relevant anymore. Feel to open up a new issue if you're still experiencing this.

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