From debb4ee34b4a0a5cb83c26e80c4bc313a3052b99 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Thu, 21 Sep 2023 11:41:07 -0700 Subject: [PATCH] added optional arg to insert --- modules/persistence/src/services/connector/index.ts | 6 +++--- modules/persistence/src/services/metadata/index.ts | 2 +- modules/persistence/src/services/pages/index.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/persistence/src/services/connector/index.ts b/modules/persistence/src/services/connector/index.ts index ea5bac0df..a43fceb5a 100644 --- a/modules/persistence/src/services/connector/index.ts +++ b/modules/persistence/src/services/connector/index.ts @@ -38,9 +38,9 @@ export const db = async () => { }; // all docs should be inserted with the buildId for the run. -export const insert = async (docs: any[], collection: string, buildId: ObjectId) => { +export const insert = async (docs: any[], collection: string, buildId: ObjectId, printTime: boolean = false) => { const timerLabel = `insert - ${collection}`; - console.time(timerLabel); + if (printTime) console.time(timerLabel); const insertSession = await db(); try { return insertSession.collection(collection).insertMany( @@ -55,7 +55,7 @@ export const insert = async (docs: any[], collection: string, buildId: ObjectId) console.error(`Error at insertion time for ${collection}: ${error}`); throw error; } finally { - console.timeEnd(timerLabel); + if (printTime) console.timeEnd(timerLabel); } }; diff --git a/modules/persistence/src/services/metadata/index.ts b/modules/persistence/src/services/metadata/index.ts index e23477ecb..74fdac5eb 100644 --- a/modules/persistence/src/services/metadata/index.ts +++ b/modules/persistence/src/services/metadata/index.ts @@ -60,7 +60,7 @@ const verifyMetadata = async (metadata: Metadata) => { export const insertMetadata = async (buildId: ObjectId, metadata: Metadata) => { try { - return insert([metadata], COLLECTION_NAME, buildId); + return insert([metadata], COLLECTION_NAME, buildId, true); } catch (error) { console.error(`Error at insertion time for ${COLLECTION_NAME}: ${error}`); throw error; diff --git a/modules/persistence/src/services/pages/index.ts b/modules/persistence/src/services/pages/index.ts index d25678f4b..38addc05a 100644 --- a/modules/persistence/src/services/pages/index.ts +++ b/modules/persistence/src/services/pages/index.ts @@ -289,7 +289,7 @@ const updatePages = async (pages: Page[], collection: string, githubUser: string export const insertAndUpdatePages = async (buildId: ObjectId, zip: AdmZip, githubUser: string) => { try { const pages = pagesFromZip(zip, githubUser); - const ops: PromiseLike[] = [insert(pages, COLLECTION_NAME, buildId)]; + const ops: PromiseLike[] = [insert(pages, COLLECTION_NAME, buildId, true)]; const featureEnabled = process.env.FEATURE_FLAG_UPDATE_PAGES; if (featureEnabled && featureEnabled.toUpperCase() === 'TRUE') {