diff --git a/app/Jobs/ProcessTellerDataJob.php b/app/Jobs/ProcessTellerDataJob.php index 0601cda..ea0bd05 100644 --- a/app/Jobs/ProcessTellerDataJob.php +++ b/app/Jobs/ProcessTellerDataJob.php @@ -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) {