diff --git a/app/Jobs/ProcessFundsTransferDataJob.php b/app/Jobs/ProcessFundsTransferDataJob.php index 91c1beb..3bfcfb7 100644 --- a/app/Jobs/ProcessFundsTransferDataJob.php +++ b/app/Jobs/ProcessFundsTransferDataJob.php @@ -186,14 +186,19 @@ { try { if (!empty($this->transferBatch)) { - // Bulk insert/update funds transfers - TempFundsTransfer::upsert( - $this->transferBatch, - ['_id'], // Unique key - array_diff((new TempFundsTransfer())->getFillable(), ['_id']) // Update columns - ); + // Process in smaller chunks for better memory management + foreach ($this->transferBatch as $entry) { + // Extract all stmt_entry_ids from the current chunk + $entryIds = array_column($entry, '_id'); - // 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 = []; } } catch (Exception $e) {