From 4e9cfb2193deb27a824f6287412808cd110cb2c2 Mon Sep 17 00:00:00 2001 From: ChaituVR Date: Mon, 16 Sep 2024 15:06:47 +0530 Subject: [PATCH] fix: Add proposalCount1d on spaces --- src/graphql/schema.gql | 1 + src/helpers/spaces.ts | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/graphql/schema.gql b/src/graphql/schema.gql index c94da62e..ab7b3fb8 100644 --- a/src/graphql/schema.gql +++ b/src/graphql/schema.gql @@ -414,6 +414,7 @@ type Space { treasuries: [Treasury] activeProposals: Int proposalsCount: Int + proposalsCount1d: Int proposalsCount7d: Int followersCount: Int followersCount7d: Int diff --git a/src/helpers/spaces.ts b/src/helpers/spaces.ts index 2ca3d3e6..d6d29780 100644 --- a/src/helpers/spaces.ts +++ b/src/helpers/spaces.ts @@ -38,6 +38,7 @@ type Metadata = { counts: { activeProposals: number; proposalsCount: number; + proposalsCount1d: number; proposalsCount7d: number; followersCount: number; followersCount7d: number; @@ -114,6 +115,7 @@ function mapSpaces() { counts: { activeProposals: spacesMetadata[id]?.counts?.activeProposals || 0, proposalsCount: space.proposal_count || 0, + proposalsCount1d: spacesMetadata[id]?.counts?.proposalsCount1d || 0, proposalsCount7d: spacesMetadata[id]?.counts?.proposalsCount7d || 0, followersCount: space.follower_count || 0, followersCount7d: spacesMetadata[id]?.counts?.followersCount7d || 0, @@ -171,16 +173,20 @@ async function getProposals(): Promise< const query = ` SELECT space, + COUNT(CASE WHEN created > (UNIX_TIMESTAMP() - 86400) THEN 1 END) AS proposalsCount1d, COUNT(id) AS proposalsCount7d FROM proposals WHERE created > (UNIX_TIMESTAMP() - 604800) GROUP BY space `; - (await db.queryAsync(query)).forEach(({ space, proposalsCount7d }) => { - results[space] ||= {}; - results[space].proposalsCount7d = proposalsCount7d; - }); + (await db.queryAsync(query)).forEach( + ({ space, proposalsCount1d, proposalsCount7d }) => { + results[space] ||= {}; + results[space].proposalsCount1d = proposalsCount1d; + results[space].proposalsCount7d = proposalsCount7d; + } + ); const activeQuery = ` SELECT