Skip to content

Commit

Permalink
fix: Add 30d proposal count to spaces (#926)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaituVR authored Sep 20, 2024
1 parent dfd7638 commit cd1a7af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/graphql/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ type Space {
proposalsCount: Int
proposalsCount1d: Int
proposalsCount7d: Int
proposalsCount30d: Int
followersCount: Int
followersCount7d: Int
votesCount: Int
Expand Down
10 changes: 7 additions & 3 deletions src/helpers/spaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Metadata = {
proposalsCount: number;
proposalsCount1d: number;
proposalsCount7d: number;
proposalsCount30d: number;
followersCount: number;
followersCount7d: number;
votesCount: number;
Expand Down Expand Up @@ -117,6 +118,7 @@ function mapSpaces() {
proposalsCount: space.proposal_count || 0,
proposalsCount1d: spacesMetadata[id]?.counts?.proposalsCount1d || 0,
proposalsCount7d: spacesMetadata[id]?.counts?.proposalsCount7d || 0,
proposalsCount30d: spacesMetadata[id]?.counts?.proposalsCount30d || 0,
followersCount: space.follower_count || 0,
followersCount7d: spacesMetadata[id]?.counts?.followersCount7d || 0,
votesCount: space.vote_count || 0,
Expand Down Expand Up @@ -174,17 +176,19 @@ async function getProposals(): Promise<
SELECT
space,
COUNT(CASE WHEN created > (UNIX_TIMESTAMP() - 86400) THEN 1 END) AS proposalsCount1d,
COUNT(id) AS proposalsCount7d
COUNT(CASE WHEN created > (UNIX_TIMESTAMP() - 604800) THEN 1 END) AS proposalsCount7d,
COUNT(id) AS proposalsCount30d
FROM proposals
WHERE created > (UNIX_TIMESTAMP() - 604800)
WHERE created > (UNIX_TIMESTAMP() - 2592000)
GROUP BY space
`;

(await db.queryAsync(query)).forEach(
({ space, proposalsCount1d, proposalsCount7d }) => {
({ space, proposalsCount1d, proposalsCount7d, proposalsCount30d }) => {
results[space] ||= {};
results[space].proposalsCount1d = proposalsCount1d;
results[space].proposalsCount7d = proposalsCount7d;
results[space].proposalsCount30d = proposalsCount30d;
}
);

Expand Down

0 comments on commit cd1a7af

Please sign in to comment.