From aaa560c2b02e7792af6c650708816ed3216132ca Mon Sep 17 00:00:00 2001 From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com> Date: Thu, 18 Jul 2024 21:29:58 +0900 Subject: [PATCH] fix: fix promises not being waited --- src/helpers/spaces.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/helpers/spaces.ts b/src/helpers/spaces.ts index f2d6e242..8efa91fa 100644 --- a/src/helpers/spaces.ts +++ b/src/helpers/spaces.ts @@ -245,10 +245,11 @@ async function getFollowers(): Promise< } async function loadSpacesMetrics() { - [getFollowers, getProposals, getVotes].forEach(async metricFn => { - const results = await metricFn(); + const metricsFn = [getFollowers, getProposals, getVotes]; + const results = await Promise.all(metricsFn.map(fn => fn())); - for (const [space, metrics] of Object.entries(results)) { + metricsFn.forEach((metricFn, i) => { + for (const [space, metrics] of Object.entries(results[i])) { if (!spacesMetadata[space]) continue; spacesMetadata[space].counts = { @@ -283,9 +284,11 @@ export async function getSpace(id: string) { export default async function run() { try { + log.info('[spaces] Start spaces refresh'); await loadSpaces(); await loadSpacesMetrics(); sortSpaces(); + log.info('[spaces] End spaces refresh'); } catch (e: any) { capture(e); log.error(`[spaces] failed to load spaces, ${JSON.stringify(e)}`);