From 0f73ccc850a6ae29d11fc491ab374e7fb369eef9 Mon Sep 17 00:00:00 2001 From: James Sasitorn Date: Thu, 19 Dec 2024 12:06:24 -0800 Subject: [PATCH] Move null filter in backfill to after await --- functions/src/backfill.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/functions/src/backfill.js b/functions/src/backfill.js index a2b0f7c..a3641be 100644 --- a/functions/src/backfill.js +++ b/functions/src/backfill.js @@ -61,17 +61,20 @@ module.exports = functions.firestore.document(config.typesenseBackfillTriggerDoc if (thisBatch.empty) { break; } - const currentDocumentsBatch = await Promise.all( - thisBatch.docs.map(async (doc) => { - const docPath = doc.ref.path; - const pathParams = utils.pathMatchesSelector(docPath, config.firestoreCollectionPath); - - if (!isGroupQuery || (isGroupQuery && pathParams !== null)) { - return await utils.typesenseDocumentFromSnapshot(doc, pathParams); - } else { - return null; - } - }).filter((doc) => doc !== null)); + const currentDocumentsBatch = ( + await Promise.all( + thisBatch.docs.map(async (doc) => { + const docPath = doc.ref.path; + const pathParams = utils.pathMatchesSelector(docPath, config.firestoreCollectionPath); + + if (!isGroupQuery || (isGroupQuery && pathParams !== null)) { + return await utils.typesenseDocumentFromSnapshot(doc, pathParams); + } else { + return null; + } + }), + ) + ).filter((doc) => doc !== null); lastDoc = thisBatch.docs.at(-1) ?? null; try {