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

feat: store proposal, vote and follower count on space #292

Merged
merged 27 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a64b8c0
feat: store proposal, vote and follower count on space
bonustrack Feb 24, 2024
faeba17
Merge branch 'master' into fabien/space-counters
bonustrack Feb 24, 2024
f36f123
Merge branch 'master' into fabien/space-counters
wa0x6e Feb 26, 2024
6fa7c39
Merge branch 'master' into fabien/space-counters
wa0x6e Feb 26, 2024
5031e82
Merge branch 'master' into fabien/space-counters
bonustrack Feb 28, 2024
e82268b
Merge branch 'master' into fabien/space-counters
bonustrack Mar 6, 2024
188a232
Merge branch 'master' into fabien/space-counters
bonustrack Mar 7, 2024
84b553e
Merge branch 'master' into fabien/space-counters
bonustrack Mar 18, 2024
3765b08
Merge branch 'master' into fabien/space-counters
wa0x6e Apr 5, 2024
16bc059
Merge branch 'master' into fabien/space-counters
ChaituVR Apr 8, 2024
87ce20f
Merge branch 'master' into fabien/space-counters
wa0x6e May 25, 2024
f9fdef1
Merge branch 'master' into fabien/space-counters
wa0x6e May 25, 2024
b894b8a
fix: ensure positive counters
wa0x6e May 25, 2024
c156078
Merge branch 'fabien/space-counters' of https://github.com/snapshot-l…
wa0x6e May 25, 2024
1e0b9e7
fix: fix missing arg
wa0x6e May 25, 2024
f090eef
fix: use total number of votes, instead of number of valid votes
wa0x6e May 25, 2024
84d2851
fix: add init script to populate spaces counters
wa0x6e May 26, 2024
5079797
chore: add tests for follow and unfollow
wa0x6e May 26, 2024
50ce0a5
Merge branch 'master' into fabien/space-counters
ChaituVR May 28, 2024
20215e6
Merge branch 'master' into fabien/space-counters
ChaituVR May 29, 2024
9e3940a
Merge branch 'master' into fabien/space-counters
wa0x6e Jun 2, 2024
5164618
Update scripts/refresh_spaces_counters.ts
wa0x6e Jun 2, 2024
f9c4366
fix: fix proposals counter being skipped when no votes
wa0x6e Jun 2, 2024
9d3f895
fix: fix missing follows_count initializer
wa0x6e Jun 2, 2024
8a45195
Merge branch 'master' into fabien/space-counters
wa0x6e Jun 30, 2024
78cf2b2
Merge branch 'master' into fabien/space-counters
wa0x6e Jun 30, 2024
a7bbced
Merge branch 'master' into fabien/space-counters
ChaituVR Jul 5, 2024
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
11 changes: 7 additions & 4 deletions src/writer/delete-proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ export async function verify(body): Promise<any> {

export async function action(body): Promise<void> {
const msg = jsonParse(body.msg);
const id = msg.payload.proposal;
const proposal = await getProposal(msg.space, msg.payload.proposal);

const id = msg.payload.proposal;
const query = `
DELETE FROM proposals WHERE id = ? LIMIT 1;
DELETE FROM votes WHERE proposal = ?;
DELETE FROM proposals WHERE id = ? LIMIT 1;
DELETE FROM votes WHERE proposal = ?;
UPDATE spaces SET proposal_count = proposal_count - 1, vote_count = vote_count - ? WHERE id = ?;
`;
await db.queryAsync(query, [id, id]);

await db.queryAsync(query, [id, id, proposal.votes, msg.space]);
wa0x6e marked this conversation as resolved.
Show resolved Hide resolved
}
13 changes: 11 additions & 2 deletions src/writer/follow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export const getFollowsCount = async (follower: string): Promise<number> => {
};

export async function verify(message): Promise<any> {
const query = `SELECT * FROM follows WHERE follower = ? AND space = ? LIMIT 1`;
const follows = await db.queryAsync(query, [message.from, message.space]);

if (follows.length !== 0) return Promise.reject('you are already following this space');

const count = await getFollowsCount(message.from);

if (count >= FOLLOWS_LIMIT_PER_USER) {
Expand All @@ -19,7 +24,11 @@ export async function verify(message): Promise<any> {
return true;
}

export async function action(message, ipfs, receipt, id): Promise<void> {
export async function action(message, ipfs, _receipt, id): Promise<void> {
const query = `
INSERT IGNORE INTO follows SET ?;
wa0x6e marked this conversation as resolved.
Show resolved Hide resolved
UPDATE spaces SET follower_count = follower_count + 1 WHERE id = ?;
`;
const params = {
id,
ipfs,
Expand All @@ -28,5 +37,5 @@ export async function action(message, ipfs, receipt, id): Promise<void> {
created: message.timestamp
};

await db.queryAsync('INSERT IGNORE INTO follows SET ?', params);
await db.queryAsync(query, [params, message.space]);
}
7 changes: 5 additions & 2 deletions src/writer/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,11 @@ export async function action(body, ipfs, receipt, id): Promise<void> {
flagged: +containsFlaggedLinks(msg.payload.body)
};

const query = 'INSERT IGNORE INTO proposals SET ?; ';
const params: any[] = [proposal];
const query = `
INSERT IGNORE INTO proposals SET ?;
wa0x6e marked this conversation as resolved.
Show resolved Hide resolved
UPDATE spaces SET proposal_count = proposal_count + 1 WHERE id = ?;
`;
const params: any[] = [proposal, space];

await db.queryAsync(query, params);
}
15 changes: 12 additions & 3 deletions src/writer/unfollow.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import db from '../helpers/mysql';

export async function verify(): Promise<any> {
export async function verify(message): Promise<any> {
const query = `SELECT * FROM follows WHERE follower = ? AND space = ? LIMIT 1`;
wa0x6e marked this conversation as resolved.
Show resolved Hide resolved
const follows = await db.queryAsync(query, [message.from, message.space]);

if (follows.length === 0) return Promise.reject('you can only unfollow a space you follow');

return true;
}

export async function action(message): Promise<void> {
const query = 'DELETE FROM follows WHERE follower = ? AND space = ? LIMIT 1';
await db.queryAsync(query, [message.from, message.space]);
const query = `
DELETE FROM follows WHERE follower = ? AND space = ? LIMIT 1;
UPDATE spaces SET follower_count = follower_count - 1 WHERE id = ?;
`;

await db.queryAsync(query, [message.from, message.space, message.space]);
}
8 changes: 7 additions & 1 deletion src/writer/vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,13 @@ export async function action(body, ipfs, receipt, id, context): Promise<void> {
);
} else {
// Store vote in dedicated table
await db.queryAsync('INSERT IGNORE INTO votes SET ?', params);
await db.queryAsync(
`
INSERT IGNORE INTO votes SET ?;
wa0x6e marked this conversation as resolved.
Show resolved Hide resolved
UPDATE spaces SET vote_count = vote_count + 1 WHERE id = ?;
`,
[params, msg.space]
);
}

// Update proposal scores and voters vp
Expand Down
Loading