refactor(webstatement): optimize ProcessTellerDataJob batching
Ubah alur proses batch pada job untuk meningkatkan efisiensi dan manajemen memori. - Mengganti metode `upsert` dengan pendekatan manual yang memecah data batch menjadi potongan lebih kecil. - Menambahkan proses penghapusan record lama berdasarkan `id_teller` sebelum melakukan insert baru untuk menghindari konflik data. - Menggunakan loop untuk memproses batch dalam potongan-potongan kecil, sehingga mengurangi beban memori. - Memastikan batch direset setelah selesai diproses untuk menghindari kebocoran data atau konflik. Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
This commit is contained in:
@@ -293,14 +293,19 @@
|
||||
{
|
||||
try {
|
||||
if (!empty($this->tellerBatch)) {
|
||||
// Bulk insert/update teller records
|
||||
Teller::upsert(
|
||||
$this->tellerBatch,
|
||||
['id_teller'], // Unique key
|
||||
array_diff(array_values(self::HEADER_MAP), ['id_teller']) // Update columns
|
||||
);
|
||||
// Process in smaller chunks for better memory management
|
||||
foreach ($this->tellerBatch as $entry) {
|
||||
// Extract all stmt_entry_ids from the current chunk
|
||||
$entryIds = array_column($entry, 'id_teller');
|
||||
|
||||
// Reset batch after processing
|
||||
// Delete existing records with these IDs to avoid conflicts
|
||||
Teller::whereIn('id_teller', $entryIds)->delete();
|
||||
|
||||
// Insert all records in the chunk at once
|
||||
Teller::insert($entry);
|
||||
}
|
||||
|
||||
// Reset entry batch after processing
|
||||
$this->tellerBatch = [];
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
|
||||
Reference in New Issue
Block a user