Change to sequential user metrics update instead of doing them all in parallel

This commit is contained in:
James Grugett 2022-02-18 19:10:02 -06:00
parent 2a5172cb48
commit 26bbb75ccd

View File

@ -22,24 +22,20 @@ export const updateUserMetrics = functions.pubsub
contracts.map((contract) => [contract.id, contract]) contracts.map((contract) => [contract.id, contract])
) )
await Promise.all( for (const user of users) {
users.map(async (user) => { const [investmentValue, creatorVolume] = await Promise.all([
const investmentValue = await computeInvestmentValue( computeInvestmentValue(user, contractsDict),
user, computeTotalVolume(user, contractsDict),
contractsDict ])
)
const totalValue = user.balance + investmentValue
const totalPnL = totalValue - user.totalDeposits const totalValue = user.balance + investmentValue
const totalPnL = totalValue - user.totalDeposits
const creatorVolume = await computeTotalVolume(user, contractsDict) await firestore.collection('users').doc(user.id).update({
totalPnLCached: totalPnL,
return firestore.collection('users').doc(user.id).update({ creatorVolumeCached: creatorVolume,
totalPnLCached: totalPnL,
creatorVolumeCached: creatorVolume,
})
}) })
) }
}) })
const computeInvestmentValue = async ( const computeInvestmentValue = async (