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])
)
await Promise.all(
users.map(async (user) => {
const investmentValue = await computeInvestmentValue(
user,
contractsDict
)
const totalValue = user.balance + investmentValue
for (const user of users) {
const [investmentValue, creatorVolume] = await Promise.all([
computeInvestmentValue(user, contractsDict),
computeTotalVolume(user, contractsDict),
])
const totalPnL = totalValue - user.totalDeposits
const totalValue = user.balance + investmentValue
const totalPnL = totalValue - user.totalDeposits
const creatorVolume = await computeTotalVolume(user, contractsDict)
return firestore.collection('users').doc(user.id).update({
totalPnLCached: totalPnL,
creatorVolumeCached: creatorVolume,
})
await firestore.collection('users').doc(user.id).update({
totalPnLCached: totalPnL,
creatorVolumeCached: creatorVolume,
})
)
}
})
const computeInvestmentValue = async (