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(flag proposal): add ability to flag proposal #679

Merged
merged 2 commits into from
Sep 28, 2023
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
7 changes: 6 additions & 1 deletion src/graphql/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,12 @@ export function formatUser(user) {

function isFlaggedProposal(proposal) {
const flaggedLinksRegex = new RegExp(flaggedLinks.join('|'), 'i');
return flaggedProposals?.includes(proposal.id) || flaggedLinksRegex.test(proposal.body);
return (
// TODO: remove this check once flagged proposals are migrated to hub db via script
flaggedProposals?.includes(proposal.id) ||
flaggedLinksRegex.test(proposal.body) ||
proposal.flagged
);
}

export function formatProposal(proposal) {
Expand Down
6 changes: 4 additions & 2 deletions src/graphql/operations/proposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ export default async function (parent, args) {
params.push(verifiedSpaces);
}

// TODO: remove part `p.id IN (?)` when flagged proposals are moved from laser DB to snapshot-sequencer DB
if (where.flagged === true && flaggedProposals.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beware of the case where this condition will not be triggered if flaggedProposals.length is 0.

Refactoring to remove p.id IN (?) has to be done before disconnecting laser database

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, thank you 🙏

searchSql += ' AND p.id IN (?)';
searchSql += ' AND (p.id IN (?) OR p.flagged = 1)';
params.push(flaggedProposals);
}

// TODO: remove part `p.id NOT IN (?)` when flagged proposals are moved from laser DB to snapshot-sequencer DB
if (where.flagged === false && flaggedProposals.length > 0) {
searchSql += ' AND p.id NOT IN (?)';
searchSql += ' AND (p.id NOT IN (?) AND p.flagged = 0)';
params.push(flaggedProposals);
}

Expand Down
4 changes: 3 additions & 1 deletion src/helpers/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ CREATE TABLE proposals (
scores_total DECIMAL(64,30) NOT NULL,
scores_updated INT(11) NOT NULL,
votes INT(12) NOT NULL,
flagged INT NOT NULL DEFAULT 0,
PRIMARY KEY (id),
INDEX ipfs (ipfs),
INDEX author (author),
Expand All @@ -57,7 +58,8 @@ CREATE TABLE proposals (
INDEX app (app),
INDEX scores_state (scores_state),
INDEX scores_updated (scores_updated),
INDEX votes (votes)
INDEX votes (votes),
INDEX flagged (flagged)
);

CREATE TABLE votes (
Expand Down