Skip to content

Commit

Permalink
fix: wrong counts (#964)
Browse files Browse the repository at this point in the history
* fix: wrong counts

* Update src/helpers/spaces.ts

Co-authored-by: Less <[email protected]>

---------

Co-authored-by: Less <[email protected]>
  • Loading branch information
ChaituVR and bonustrack authored Dec 20, 2024
1 parent 8ab0f00 commit 2abe545
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions src/helpers/spaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,15 @@ async function loadSpaces() {
}

async function getProposals(): Promise<
Record<string, { activeProposals: number; proposalsCount7d: number }>
Record<
string,
{
activeProposals: number;
proposalsCount1d: number;
proposalsCount7d: number;
proposalsCount30d: number;
}
>
> {
const ts = parseInt((Date.now() / 1e3).toFixed());
const results = {};
Expand Down Expand Up @@ -250,19 +258,23 @@ async function getFollowers(): Promise<
}

async function loadSpacesMetrics() {
const metricsFn = [getFollowers, getProposals, getVotes];
const results = await Promise.all(metricsFn.map(fn => fn()));

metricsFn.forEach((metricFn, i) => {
for (const [space, metrics] of Object.entries(results[i])) {
if (!spacesMetadata[space]) continue;

spacesMetadata[space].counts = {
...spacesMetadata[space].counts,
...metrics
};
}
log.info(`[spaces] ${metricFn.name.replace('get', '')} metrics loaded`);
const results = await Promise.all([
getFollowers(),
getProposals(),
getVotes()
]);

const [followerMetrics, proposalMetrics, voteMetrics] = results;
Object.keys(spacesMetadata).forEach(space => {
spacesMetadata[space].counts = {
...spacesMetadata[space].counts,
activeProposals: proposalMetrics[space]?.activeProposals || 0,
proposalsCount1d: proposalMetrics[space]?.proposalsCount1d || 0,
proposalsCount7d: proposalMetrics[space]?.proposalsCount7d || 0,
proposalsCount30d: proposalMetrics[space]?.proposalsCount30d || 0,
followersCount7d: followerMetrics[space]?.followersCount7d || 0,
votesCount7d: voteMetrics[space]?.votesCount7d || 0
};
});
}

Expand Down

0 comments on commit 2abe545

Please sign in to comment.