ExportAction crash the website
I'm managing a large quantity of orders and related LineItems for a e-Commerce. I created an ExportAction in order to export the LineItems according to some form data used as filters.
When I try to run the ExportAction, I see the window that allow you to select the columns, and when I click "Export", it stays loading until I get a timeout.
If I pick, via filters, a small amount of orders (for example, from date two days ago) it's working, but it cannot process it when I try to load all of them.
In my .env file, I have QUEUE_CONNECTION=database
I understand that if the export was done at the moment, it could fail, but it's taking a lot of time to add it to the queue. How can I solve this?
Code of the Form
// Date filters
Section::make('Data')
->columnSpan(['sm' => 9, 'lg' => 3])
->columns(['sm' => 2, 'lg' => 2])
->schema([
// Select to filter the start date
DatePicker::make('start_date_export')
->label('Data inizio')
->format('d/m/Y')
->displayFormat('d/m/Y')
->columnSpan(['sm' => 2, 'lg' => 2]),
]),
Code of the Export Action:
ExportAction::make()
->exporter(LineItemExporter::class)
->label('Esporta Ordini')
->fileName('ordini')
->chunkSize(200)
->extraAttributes([
'style' => 'background-color: #03B89D'
])
->modifyQueryUsing(function (Builder $query) {
$formData = $this->getFormData();
$start_date = $formData['start_date_export'] ?? null;
$order_query = Order::query();
// // DATE FILTERS
if ($start_date) {
// Fetch orders from the start date (formatted as Y-m-d)
$order_query->where('created_at', '>=', Carbon::parse($start_date)->format('Y-m-d'));
}
// Line Items Query
$query->whereIn('order_id', $order_query->pluck('id'));
})
Code of the Exporter
public static function getColumns(): array
{
$numero_ordine = ExportColumn::make('order.id')
->label('NumeroOrdine');
return [
$numero_ordine
];
}
There is a larger number of columns, but I reduced it to do a summary here.
Please or to participate in this conversation.