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
scout:import performance issues when toSearchableArray contains relationships #329
Comments
Cross ref algolia/scout-extended#90 |
Did some research for this. The problem is indeed that the public function searchableWith(): array
{
return ['provider', 'receiver', 'category', 'subcategory'];
} Which then would be used in the |
Gonna mark this as a feature request rather than a bug because the temp solution would indeed be to use the |
for now you could just override /**
* Make all instances of the model searchable.
*
* @return void
*/
public static function makeAllSearchable()
{
$self = new static();
$softDeletes = in_array(SoftDeletes::class, class_uses_recursive(get_called_class())) &&
config('scout.soft_delete', false);
$self->newQuery()
->with([
/*******************************
your relations goes here
*******************************/
])
->when($softDeletes, function ($query) {
$query->withTrashed();
})
->orderBy($self->getKeyName())
->searchable();
}
|
But it is not work when queue is true. |
Closing this since the PR was rejected. We probably won't be pursuing this any further. |
I recently made a model Searchable using Scout and Algolia. When running scout:import in production the whole production (Google App Engine) crashed. There was just over 15K records that needed to import. The SQL queries were going out of control (2000-2500 queries/second) and our production environment was down until the queued jobs all failed.
Someone in Discord (@fitztrev) mentioned that they ran into the same issue and tracked it down to the lack of eager loading of relationships mentioned in toSearchableArray(). Here is the method in my case:
If the relationships aren't eager loaded it would make sense that this would generate an obscene number of queries.
I believe I could use
protected $with = ['provider', 'receiver', 'category', 'subcategory'];
on the object, but that would mean I'm eager loading the relationships every single time I have an instance of this object, which I don't always want/need to do.The text was updated successfully, but these errors were encountered: