Skip to content

Commit

Permalink
fix: fix promises not being waited
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e committed Jul 18, 2024
1 parent 3600005 commit aaa560c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/helpers/spaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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)}`);
Expand Down

0 comments on commit aaa560c

Please sign in to comment.