Memory Exhaustion in table

Hey I am running into an issue where memory is exhausted. I have this select:
Select::make('product_id')
->hidden(function () use ($productId) {
return $productId !== null;
})
->options(function (Get $get) {
$supplierId = $get('../../supplier_id');
if ($supplierId) {
return Product::select('id', DB::raw("CONCAT(item_code, ' - ', item_description) as concatenated_value"))
->where('supplier_id', $supplierId)
->where('available', true)
->pluck('concatenated_value', 'id')
->toArray();
}

return ['Selecteer eerst een merk'];
})
->label('Product')
->searchable()
->preload()
->disabled(fn(Get $get) => $get('../../sent'))
->columnSpan(2)
->required(),
Select::make('product_id')
->hidden(function () use ($productId) {
return $productId !== null;
})
->options(function (Get $get) {
$supplierId = $get('../../supplier_id');
if ($supplierId) {
return Product::select('id', DB::raw("CONCAT(item_code, ' - ', item_description) as concatenated_value"))
->where('supplier_id', $supplierId)
->where('available', true)
->pluck('concatenated_value', 'id')
->toArray();
}

return ['Selecteer eerst een merk'];
})
->label('Product')
->searchable()
->preload()
->disabled(fn(Get $get) => $get('../../sent'))
->columnSpan(2)
->required(),
If I comment it out it will work smooth but this error which selects about 20k records to choose from or to search from kills the application. Any suggestion on how to improve the performance? This select is used in a repeater. So it could be that for each record in the repeater it will execute this query.
5 Replies
Ateus
Ateus11mo ago
Do you need to show all 20k options, or can they be searched?
JJSanders
JJSandersOP11mo ago
They can be searched It doesn't work when I remove preload either This issue is really blocking me. Does anyone have an idea what goes wrong over here?
Solution
nya
nya11mo ago
Just use ->getSearchResultsUsing(), and ->getOptionLabelUsing() (you have to use both), and in them, you can add a query with a limit, like you can see in the example. The only downside (or upside?) is that you have to implement the searching yourself. If you're using this, probably remove the call to ->preload(), I don't think it does anything in this case
JJSanders
JJSandersOP11mo ago
Hey thanks for your reply. This will help me with searching. The problem is before searching namely loading som options into the select. I guess I would load maybe the first 25 products and then they should be able to search for the other ones... I think this did the trick. Altough it is still kind of slow , it worked. So I preloaded 50 items and then added the searchable functions to be able to find the other stuff
Want results from more Discord servers?
Add your server