Tweak logic of calling cloud functions in batches

This commit is contained in:
James Grugett 2022-05-01 11:21:54 -04:00
parent c880e164f9
commit 65a8042414
2 changed files with 12 additions and 8 deletions

View File

@ -24,10 +24,12 @@ export const updateRecommendations = functions.pubsub
userBatches.push(users.slice(i, i + batchSize))
}
for (const batch of userBatches) {
await new Promise((resolve) => setTimeout(resolve, 100))
callCloudFunction('updateRecommendationsBatch', { users: batch })
}
await Promise.all(
userBatches.map(async (batch, i) => {
await new Promise((resolve) => setTimeout(resolve, 100 * i))
await callCloudFunction('updateRecommendationsBatch', { users: batch })
})
)
})
export const updateRecommendationsBatch = functions.https.onCall(

View File

@ -28,10 +28,12 @@ export const updateFeed = functions.pubsub
const contracts = await getFeedContracts()
const users = await getValues<User>(firestore.collection('users'))
for (const user of users) {
await new Promise((resolve) => setTimeout(resolve, 10))
callCloudFunction('updateUserFeed', { user, contracts })
}
await Promise.all(
users.map(async (user, i) => {
await new Promise((resolve) => setTimeout(resolve, 10 * i))
await callCloudFunction('updateUserFeed', { user, contracts })
})
)
})
export const updateUserFeed = functions.https.onCall(