refactor(webstatement): optimize ATM transaction processing
- Ubah mekanisme pengolahan batch transaksi ATM agar lebih efisien dan hemat memori. - Hapus proses `upsert` secara langsung dan ganti dengan pendekatan berikut: 1. Iterasi data batch dalam chunk kecil untuk menghindari konsumsi memori berlebih. 2. Hapus data yang sudah ada berdasarkan `transaction_id` untuk menghindari konflik saat insert ulang. 3. Gunakan metode `insert` untuk memasukkan data sekaligus per chunk. - Tambahkan logika reset batch setelah selesai pengolahan. - Tingkatkan skalabilitas dan stabilitas alur pengolahan data dengan mengurangi beban memori saat pemrosesan data besar. Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
This commit is contained in:
@@ -223,14 +223,19 @@
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (!empty($this->atmTransactionBatch)) {
|
if (!empty($this->atmTransactionBatch)) {
|
||||||
// Bulk insert/update ATM transactions
|
// Process in smaller chunks for better memory management
|
||||||
AtmTransaction::upsert(
|
foreach ($this->atmTransactionBatch as $entry) {
|
||||||
$this->atmTransactionBatch,
|
// Extract all stmt_entry_ids from the current chunk
|
||||||
['transaction_id'], // Unique key
|
$entryIds = array_column($entry, 'transaction_id');
|
||||||
array_values(array_diff(self::HEADER_MAP, ['id'])) // Update columns (all except transaction_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Reset batch after processing
|
// Delete existing records with these IDs to avoid conflicts
|
||||||
|
AtmTransaction::whereIn('transaction_id', $entryIds)->delete();
|
||||||
|
|
||||||
|
// Insert all records in the chunk at once
|
||||||
|
AtmTransaction::insert($entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset entry batch after processing
|
||||||
$this->atmTransactionBatch = [];
|
$this->atmTransactionBatch = [];
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user