From 8ca438f245a45186626f4f5b34d1ed7473667c0e Mon Sep 17 00:00:00 2001 From: Ru Chern Chong Date: Wed, 13 Dec 2023 01:59:21 +0800 Subject: [PATCH] Speed up computation --- packages/core/src/datasets.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/core/src/datasets.ts b/packages/core/src/datasets.ts index abc3825..d3f558f 100644 --- a/packages/core/src/datasets.ts +++ b/packages/core/src/datasets.ts @@ -48,11 +48,11 @@ export const updater = async () => { const result = await db.collection("cars").insertMany(parsedData); console.log(`${result.insertedCount} document(s) inserted`); } else { + const existingDataMap = new Map( + existingData.map((item) => [item.month, item]), + ); const newDataToInsert = parsedData.filter( - (newItem) => - !existingData.some( - (existingItem) => existingItem.month === newItem.month, - ), + (newItem) => !existingDataMap.has(newItem.month), ); if (newDataToInsert.length > 0) {