Running Bulk Action with 'Select All' times out or runs out of memory
Hello,
I have a table with lots of rows and running a bulk action while 'Select All' is checked wither returns a timeout error (from cloudflare) or an internal server error where the PHP process runs out of memory.
In the action, I'm simple chunking the selected records and dispatching a job for each chunk.
I realise that the cause of the issue is the fact that filament loads all the selected records into memory before passing them down to the action's closure.
If this isn't an issue the maintainers want to jump on quickly, 'm thinking of modifying this behaviour such that only the keys/PK of the selected table items are passed down, basically something more memory efficient. However, so far, I've had no luck finding where filament processes the action callback.
Solution:Jump to solution
I just realized you can already access the list of selected IDs:
```php
->action(function ($livewire) {
// $livewire->selectedTableRecords
})...
7 Replies
How many rows? How much memory?
You should look how to optimise it
For our UserResource, we have a bulk action that admin can use to send emails to selected users. There are almost 42k users on the system and we have the timeout error when all users are selected and the bulk action is submitted
You should look how to optimise itExactly. I'm looking into filament code for where it executes bulk action to see where I might be able to tweak, if you could point me there. Essentially, filament is loading all the 42k rows into memory before executing the action which is not good for obvious reasons. Right now I've set memory limit in php.ini at 1.5gb
Hi @eoncode Can't say I'm too familiar with the internals but I've been digging quite a bit in the context of my current project (and just for fun π€)
I believe what you're referring to is this:
https://github.com/filamentphp/filament/blob/2.x/packages/tables/src/Concerns/HasBulkActions.php#L186
The call to and use a custom BulkAction class where you can inject a list of IDs instead of the default
https://github.com/filamentphp/filament/blob/2.x/packages/tables/src/Actions/BulkAction.php#L58
getSelectedTableRecords()
loads all records for the current selection.
Something you could explore to optimize it would be to override the Table method (to prevent loading all records in memory)
$records
Solution
I just realized you can already access the list of selected IDs:
@pboivin awesome. thanks π
this looks like what I need
Or you ca use:
I think emmann is trying to access the IDs without loading the collection of records