Skip to content

Commit

Permalink
fix: Add proposalCount1d on spaces (#925)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaituVR committed Sep 16, 2024
1 parent 926c930 commit ef1490c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/graphql/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ type Space {
treasuries: [Treasury]
activeProposals: Int
proposalsCount: Int
proposalsCount1d: Int
proposalsCount7d: Int
followersCount: Int
followersCount7d: Int
Expand Down
14 changes: 10 additions & 4 deletions src/helpers/spaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Metadata = {
counts: {
activeProposals: number;
proposalsCount: number;
proposalsCount1d: number;
proposalsCount7d: number;
followersCount: number;
followersCount7d: number;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ef1490c

Please sign in to comment.