Change to sequential user metrics update instead of doing them all in parallel
This commit is contained in:
parent
2a5172cb48
commit
26bbb75ccd
|
@ -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 (
|
||||||
|
|
Loading…
Reference in New Issue
Block a user