Performance issue with BulkAction : selectedRecords (only IDs, not Eloquent?)

Hi guys, I'm working on a Filament app and I need to add some exports features. We have a lot of tables and data, so both the official Filament Export action and Dennis Koch package are not suitable for us. I'm using Laravel Excel and DB Query without Eloquent, but I wish I could offer my users a way to filter the data before export them. For that, I'm trying to use BulkAction, however the $selectedRecords is an Eloquent collection and when using the Select All it makes my app crashes. Is that a way for the table select option to only retrieve an array of ID and not load the entire Eloquent collection? I know this is a very specific request and maybe it's not possible, but I just want to be sure before switching to a custom solution.
5 Replies
Benjamin
BenjaminOP2mo ago
A possibility to fix it without ruling out Eloquent could be to use chunk() ? Maybe it's already the case, idk. Up ☝️
Dennis Koch
Dennis Koch2mo ago
Do you actually need the selection or would be searching/filtering okay? Then you could use a table header action and use the table query. I think you can also access the property on the livewire component directly
Benjamin
BenjaminOP2mo ago
The searching/filtering could be enough. I'll try this, thanks !
->headerActions([
Actions\Action::make('export-test')
->action(fn (HasTable $livewire) => dump($table->getFilteredTableQuery()->count())),
])
->headerActions([
Actions\Action::make('export-test')
->action(fn (HasTable $livewire) => dump($table->getFilteredTableQuery()->count())),
])
Okay it works like that, I will try to combine that and your Filament Excel package 🧐 It's working but not sure this is optimal. I added this method in my ListMissions page :
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
ExportAction::make()->exports([
MissionExport::make()
->modifyQueryUsing(fn (HasTable $livewire) => $livewire->getFilteredTableQuery()
->with([
'collaborator',
'coordinator',
'days',
'group',
'groupLabel',
'institution.canton',
'latestConfirmation',
'proposals',
'trainingLevels',
])
->withCount(['proposals', 'workedDays'])
->toBase()
->orderBy('missions.id', 'desc')),
]),
// Actions\Action::make('export-test')
// ->action(fn () => dump($this->getFilteredTableQuery()->count())),
// Actions\ActionGroup::make([
// MissionHoursCheckExportAction::action(),
// ])
// ->label('Exports')
// ->icon('heroicon-m-arrow-up-on-square')
// ->outlined()
// ->color('info')
// ->button(),
];
}
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
ExportAction::make()->exports([
MissionExport::make()
->modifyQueryUsing(fn (HasTable $livewire) => $livewire->getFilteredTableQuery()
->with([
'collaborator',
'coordinator',
'days',
'group',
'groupLabel',
'institution.canton',
'latestConfirmation',
'proposals',
'trainingLevels',
])
->withCount(['proposals', 'workedDays'])
->toBase()
->orderBy('missions.id', 'desc')),
]),
// Actions\Action::make('export-test')
// ->action(fn () => dump($this->getFilteredTableQuery()->count())),
// Actions\ActionGroup::make([
// MissionHoursCheckExportAction::action(),
// ])
// ->label('Exports')
// ->icon('heroicon-m-arrow-up-on-square')
// ->outlined()
// ->color('info')
// ->button(),
];
}
It works, but I can't move the modifyQueryUsing() inside my MissionExport class because I can't access the livewire component inside the setUp method. Maybe a better solution would be to be able to use a callback on the exports() method of the ExportAction, and override the getQuery() default behavior by passing a custom query, maybe as an optional parameter in the make() method of the ExcelExport class ? What do you think @Dennis Koch ?
Dennis Koch
Dennis Koch2mo ago
I think ->fromTable() should already do this.
but I can't move the modifyQueryUsing() inside my MissionExport class because I can't access the livewire component inside the setUp method
It's just the same as you already did? $this->modifyQueryUsing(fn ($livewire) => ...). Just put it in the setUp()
Benjamin
BenjaminOP2mo ago
I'll try it next week and give you a feedback, thanks !

Did you find this page helpful?