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 {
|
try {
|
||||||
if (!empty($this->tellerBatch)) {
|
if (!empty($this->tellerBatch)) {
|
||||||
// Bulk insert/update teller records
|
// Process in smaller chunks for better memory management
|
||||||
Teller::upsert(
|
foreach ($this->tellerBatch as $entry) {
|
||||||
$this->tellerBatch,
|
// Extract all stmt_entry_ids from the current chunk
|
||||||
['id_teller'], // Unique key
|
$entryIds = array_column($entry, 'id_teller');
|
||||||
array_diff(array_values(self::HEADER_MAP), ['id_teller']) // Update columns
|
|
||||||
);
|
|
||||||
|
|
||||||
// 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 = [];
|
$this->tellerBatch = [];
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user