diff --git a/functions/src/update-recommendations.ts b/functions/src/update-recommendations.ts index e7fd9a2a..07abc257 100644 --- a/functions/src/update-recommendations.ts +++ b/functions/src/update-recommendations.ts @@ -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( diff --git a/functions/src/update-user-feed.ts b/functions/src/update-user-feed.ts index 57a15bb6..cae77ee4 100644 --- a/functions/src/update-user-feed.ts +++ b/functions/src/update-user-feed.ts @@ -28,10 +28,12 @@ export const updateFeed = functions.pubsub const contracts = await getFeedContracts() const users = await getValues(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(