From b5d5b1c2724cf7edaae024e4df8e63ef98ecc5f9 Mon Sep 17 00:00:00 2001 From: faisolavolut Date: Thu, 20 Nov 2025 15:00:40 +0700 Subject: [PATCH] fix: optimize existing record lookup in database sync process --- src/controllers/syncController.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/controllers/syncController.ts b/src/controllers/syncController.ts index c57ea3d..44ba41a 100644 --- a/src/controllers/syncController.ts +++ b/src/controllers/syncController.ts @@ -142,12 +142,11 @@ async function processDatabaseSync(database: any) { select: { id: true, c_invoice_id: true }, }); - const existingMap = new Map( - existingRecords.map((record) => [record.c_invoice_id, record.id]) - ); - for (const op of ops) { - const existingId = existingMap.get(op.c_invoice_id); + const existData = existingRecords.find( + (record) => record.c_invoice_id === op.c_invoice_id + ); + const existingId = existData ? existData.id : null; if (existingId) { transactions.push( db.rv_openitem.update({