Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add proposalCount1d on spaces #925

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading