Tweak logic of calling cloud functions in batches
This commit is contained in:
parent
c880e164f9
commit
65a8042414
|
@ -24,10 +24,12 @@ export const updateRecommendations = functions.pubsub
|
||||||
userBatches.push(users.slice(i, i + batchSize))
|
userBatches.push(users.slice(i, i + batchSize))
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const batch of userBatches) {
|
await Promise.all(
|
||||||
await new Promise((resolve) => setTimeout(resolve, 100))
|
userBatches.map(async (batch, i) => {
|
||||||
callCloudFunction('updateRecommendationsBatch', { users: batch })
|
await new Promise((resolve) => setTimeout(resolve, 100 * i))
|
||||||
}
|
await callCloudFunction('updateRecommendationsBatch', { users: batch })
|
||||||
|
})
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
export const updateRecommendationsBatch = functions.https.onCall(
|
export const updateRecommendationsBatch = functions.https.onCall(
|
||||||
|
|
|
@ -28,10 +28,12 @@ export const updateFeed = functions.pubsub
|
||||||
const contracts = await getFeedContracts()
|
const contracts = await getFeedContracts()
|
||||||
const users = await getValues<User>(firestore.collection('users'))
|
const users = await getValues<User>(firestore.collection('users'))
|
||||||
|
|
||||||
for (const user of users) {
|
await Promise.all(
|
||||||
await new Promise((resolve) => setTimeout(resolve, 10))
|
users.map(async (user, i) => {
|
||||||
callCloudFunction('updateUserFeed', { user, contracts })
|
await new Promise((resolve) => setTimeout(resolve, 10 * i))
|
||||||
}
|
await callCloudFunction('updateUserFeed', { user, contracts })
|
||||||
|
})
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
export const updateUserFeed = functions.https.onCall(
|
export const updateUserFeed = functions.https.onCall(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user