Fix weird new crash in updateMetrics: contract.id missing?

This commit is contained in:
James Grugett 2022-08-28 00:11:13 -05:00
parent e4f46c48f1
commit 9dd23b4a08

View File

@ -55,16 +55,18 @@ export const updateMetricsCore = async () => {
const now = Date.now() const now = Date.now()
const betsByContract = groupBy(bets, (bet) => bet.contractId) const betsByContract = groupBy(bets, (bet) => bet.contractId)
const contractUpdates = contracts.map((contract) => { const contractUpdates = contracts
const contractBets = betsByContract[contract.id] ?? [] .filter((contract) => contract.id)
return { .map((contract) => {
doc: firestore.collection('contracts').doc(contract.id), const contractBets = betsByContract[contract.id] ?? []
fields: { return {
volume24Hours: computeVolume(contractBets, now - DAY_MS), doc: firestore.collection('contracts').doc(contract.id),
volume7Days: computeVolume(contractBets, now - DAY_MS * 7), fields: {
}, volume24Hours: computeVolume(contractBets, now - DAY_MS),
} volume7Days: computeVolume(contractBets, now - DAY_MS * 7),
}) },
}
})
await writeAsync(firestore, contractUpdates) await writeAsync(firestore, contractUpdates)
log(`Updated metrics for ${contracts.length} contracts.`) log(`Updated metrics for ${contracts.length} contracts.`)