From d99928d16ee567aef7bf06013b8c2f1cc501ee47 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Fri, 6 May 2022 16:23:01 -0400 Subject: [PATCH] Parallelize ante creation --- functions/src/create-contract.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/functions/src/create-contract.ts b/functions/src/create-contract.ts index 7044c6cc..79fe63ba 100644 --- a/functions/src/create-contract.ts +++ b/functions/src/create-contract.ts @@ -121,7 +121,7 @@ export const createContract = functions closeTime, tags ?? [], 100, - 1, + 0, 100 ) @@ -188,16 +188,18 @@ export const createContract = functions ante ) - for (let i = 0; i < antes.length; i++) { - const anteBetDoc = firestore - .collection(`contracts/${contract.id}/bets`) - .doc() + await Promise.all( + antes.map(async (ante) => { + const anteBetDoc = firestore + .collection(`contracts/${contract.id}/bets`) + .doc() - await anteBetDoc.set({ - id: anteBetDoc.id, - ...antes[i], + await anteBetDoc.set({ + id: anteBetDoc.id, + ...ante, + }) }) - } + ) } }