From a90e9b7083870d6f9f475641b5a34fcb41df0859 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Thu, 3 Feb 2022 00:19:59 -0600 Subject: [PATCH] Reorder fold page queries to be more in parallel --- web/pages/fold/[...slugs]/index.tsx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/web/pages/fold/[...slugs]/index.tsx b/web/pages/fold/[...slugs]/index.tsx index 6841cf27..e93bdbbb 100644 --- a/web/pages/fold/[...slugs]/index.tsx +++ b/web/pages/fold/[...slugs]/index.tsx @@ -48,6 +48,10 @@ export async function getStaticProps(props: { params: { slugs: string[] } }) { const contracts = fold ? await getFoldContracts(fold).catch((_) => []) : [] + const betsPromise = Promise.all( + contracts.map((contract) => listAllBets(contract.id)) + ) + const [contractComments, contractRecentBets] = await Promise.all([ Promise.all( contracts.map((contract) => listAllComments(contract.id).catch((_) => [])) @@ -79,17 +83,16 @@ export async function getStaticProps(props: { params: { slugs: string[] } }) { contractComments[contracts.findIndex((c) => c.id === contract.id)] ) - const curator = await curatorPromise - - const bets = await Promise.all( - contracts.map((contract) => listAllBets(contract.id)) - ) + const bets = await betsPromise const creatorScores = scoreCreators(contracts, bets) - const topCreators = await toTopUsers(creatorScores) - const traderScores = scoreTraders(contracts, bets) - const topTraders = await toTopUsers(traderScores) + const [topCreators, topTraders] = await Promise.all([ + toTopUsers(creatorScores), + toTopUsers(traderScores), + ]) + + const curator = await curatorPromise return { props: {