refactor(webstatement): optimalkan pemrosesan batch transfer dana
- Mengubah mekanisme pemrosesan `transferBatch` menjadi berbasis chunk untuk mengoptimalkan penggunaan memori. - Menambahkan logika penghapusan data lama dengan `_id` terkait sebelum menyisipkan data baru untuk menghindari konflik. - Mengganti metode `upsert` dengan kombinasi `delete` dan `insert` untuk lebih fleksibel dalam penanganan data. - Memastikan batch transfer diatur ulang setelah selesai diproses. Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
This commit is contained in:
@@ -186,14 +186,19 @@
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (!empty($this->transferBatch)) {
|
if (!empty($this->transferBatch)) {
|
||||||
// Bulk insert/update funds transfers
|
// Process in smaller chunks for better memory management
|
||||||
TempFundsTransfer::upsert(
|
foreach ($this->transferBatch as $entry) {
|
||||||
$this->transferBatch,
|
// Extract all stmt_entry_ids from the current chunk
|
||||||
['_id'], // Unique key
|
$entryIds = array_column($entry, '_id');
|
||||||
array_diff((new TempFundsTransfer())->getFillable(), ['_id']) // Update columns
|
|
||||||
);
|
|
||||||
|
|
||||||
// Reset transfer batch after processing
|
// Delete existing records with these IDs to avoid conflicts
|
||||||
|
TempFundsTransfer::whereIn('_id', $entryIds)->delete();
|
||||||
|
|
||||||
|
// Insert all records in the chunk at once
|
||||||
|
TempFundsTransfer::insert($entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset entry batch after processing
|
||||||
$this->transferBatch = [];
|
$this->transferBatch = [];
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user