You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Laravel Scout has a companion method to map, lazyMap, which uses a generator under the hood to keep memory usage low. That lazyMap method doesn't play nicely with Scout Extended, in basically the same way as the underlying issue in #279—it uses Algolia's objectID to retrieve models, which it expects to be the actual model key, but which with Scout Extended installed is actually something like App\Event::20.
The map method does this too, but Scout Extended overrides it and accounts for the primary key thing inside the ModelsResolver class.
I can't switch to using the map method because the code calling lazyMap is inside Laravel Nova, in the global search code. I'll file an issue there too.
Ideally Scout Extended would also override lazyMap, with functionality similar to map but returning a generator or lazy collection if possible. I'll try to take a crack at a PR for that in the next week or two.
In the meantime, for anyone else running into this, I managed to work around it by overriding the Laravel\Nova\Query\Builder class:
// In the `register` method of `app/Providers/NovaServiceProvider.php`useApp\Nova\Builder;
useLaravel\Nova\Contracts\QueryBuilder;
$this->app->bind(QueryBuilder::class, fn ($app, $parameters) => newBuilder(...$parameters));
// `app/Nova/Builder.php`useIlluminate\Support\LazyCollection;
useLaravel\Nova\Query\BuilderasNova;
class Builder extends Nova
{
publicfunctioncursor()
{
$queryBuilder = $this->applyQueryCallbacks($this->queryBuilder);
// Remove or comment out this part// if (method_exists($queryBuilder, 'cursor')) {// return $queryBuilder->cursor();// }return LazyCollection::make(function () use ($queryBuilder) {
yieldfrom$queryBuilder->get()
->each(function ($result) {
yield$result;
});
});
}
}
The text was updated successfully, but these errors were encountered:
Description
Laravel Scout has a companion method to
map
,lazyMap
, which uses a generator under the hood to keep memory usage low. ThatlazyMap
method doesn't play nicely with Scout Extended, in basically the same way as the underlying issue in #279—it uses Algolia'sobjectID
to retrieve models, which it expects to be the actual model key, but which with Scout Extended installed is actually something likeApp\Event::20
.The
map
method does this too, but Scout Extended overrides it and accounts for the primary key thing inside theModelsResolver
class.I can't switch to using the
map
method because the code callinglazyMap
is inside Laravel Nova, in the global search code. I'll file an issue there too.Ideally Scout Extended would also override
lazyMap
, with functionality similar tomap
but returning a generator or lazy collection if possible. I'll try to take a crack at a PR for that in the next week or two.In the meantime, for anyone else running into this, I managed to work around it by overriding the
Laravel\Nova\Query\Builder
class:The text was updated successfully, but these errors were encountered: