refactor(webstatement): optimalkan pemrosesan batch data bill detail
- Mengubah mekanisme pemrosesan batch `billDetailBatch` menjadi pemrosesan per chunk untuk manajemen memori yang lebih baik. - Menambahkan langkah penghapusan data eksisting berdasarkan `stmt_entry_ids` sebelum melakukan insert untuk menghindari konflik data. - Mengganti metode `upsert` dengan kombinasi `delete` dan `insert` untuk tiap chunk data. - Menyisipkan komentar untuk memberikan penjelasan yang lebih rinci terkait proses chunking. - Memastikan batch `billDetailBatch` di-reset setelah selesai diproses. Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
This commit is contained in:
@@ -182,14 +182,19 @@
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (!empty($this->billDetailBatch)) {
|
if (!empty($this->billDetailBatch)) {
|
||||||
// Bulk insert/update bill details
|
// Process in smaller chunks for better memory management
|
||||||
TempBillDetail::upsert(
|
foreach ($this->billDetailBatch as $entry) {
|
||||||
$this->billDetailBatch,
|
// Extract all stmt_entry_ids from the current chunk
|
||||||
['_id'], // Unique key
|
$entryIds = array_column($entry, '_id');
|
||||||
array_diff((new TempBillDetail())->getFillable(), ['_id']) // Update columns
|
|
||||||
);
|
|
||||||
|
|
||||||
// Reset batch after processing
|
// Delete existing records with these IDs to avoid conflicts
|
||||||
|
TempBillDetail::whereIn('_id', $entryIds)->delete();
|
||||||
|
|
||||||
|
// Insert all records in the chunk at once
|
||||||
|
TempBillDetail::insert($entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset entry batch after processing
|
||||||
$this->billDetailBatch = [];
|
$this->billDetailBatch = [];
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user