Merge pull request #10847 from WayneHarris/3.x-fix-chunk-order-in-exports

fix(exports) update prepare csv job to account for order by
This commit is contained in:
Dan Harrin
2024-01-18 15:31:21 +00:00
committed by GitHub
@@ -102,15 +102,19 @@ class PrepareCsvExport implements ShouldQueue
return;
}
$baseQuery = $query->toBase();
$sortDirection = $baseQuery->orders[0]['direction'] ?? 'asc';
$query->toBase()
$baseQuery
->select([$query->getModel()->getQualifiedKeyName()])
->chunkById(
->orderedChunkById(
$this->chunkSize * 10,
fn (Collection $records) => $dispatchRecords(
Arr::pluck($records->all(), $keyName),
),
$keyName,
descending: $sortDirection === 'desc',
);
}