From 9dd23b4a088ee75015adf2e9c95dd7e7983175c1 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Sun, 28 Aug 2022 00:11:13 -0500 Subject: [PATCH] Fix weird new crash in updateMetrics: contract.id missing? --- functions/src/update-metrics.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/functions/src/update-metrics.ts b/functions/src/update-metrics.ts index a2e72053..9ef3fb10 100644 --- a/functions/src/update-metrics.ts +++ b/functions/src/update-metrics.ts @@ -55,16 +55,18 @@ export const updateMetricsCore = async () => { const now = Date.now() const betsByContract = groupBy(bets, (bet) => bet.contractId) - const contractUpdates = contracts.map((contract) => { - const contractBets = betsByContract[contract.id] ?? [] - return { - doc: firestore.collection('contracts').doc(contract.id), - fields: { - volume24Hours: computeVolume(contractBets, now - DAY_MS), - volume7Days: computeVolume(contractBets, now - DAY_MS * 7), - }, - } - }) + const contractUpdates = contracts + .filter((contract) => contract.id) + .map((contract) => { + const contractBets = betsByContract[contract.id] ?? [] + return { + doc: firestore.collection('contracts').doc(contract.id), + fields: { + volume24Hours: computeVolume(contractBets, now - DAY_MS), + volume7Days: computeVolume(contractBets, now - DAY_MS * 7), + }, + } + }) await writeAsync(firestore, contractUpdates) log(`Updated metrics for ${contracts.length} contracts.`)