-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add user_space table to collect user's votes and proposals coun…
…t per space
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'dotenv/config'; | ||
import db from '../src/helpers/mysql'; | ||
|
||
// Usage: yarn ts-node scripts/generate_user_space_counters.ts | ||
async function main() { | ||
console.log('Inserting/Updating proposals_count'); | ||
const proposalsCountRes = await db.queryAsync( | ||
`INSERT INTO user_space (proposals_count, user_id, space_id) | ||
(select * from (select count(id) as proposals_count, author, space from proposals group by author, space) as t) | ||
ON DUPLICATE KEY UPDATE proposals_count = t.proposals_count` | ||
); | ||
console.log(proposalsCountRes); | ||
|
||
console.log('Inserting/Updating votes_count'); | ||
const votesCountRes = await db.queryAsync( | ||
`INSERT INTO user_space (votes_count, user_id, space_id) | ||
(select * from (select count(id) as votes_count, voter, space from votes group by voter, space) as t) | ||
ON DUPLICATE KEY UPDATE votes_count = t.votes_count` | ||
); | ||
console.log(votesCountRes); | ||
} | ||
|
||
(async () => { | ||
try { | ||
await main(); | ||
process.exit(0); | ||
} catch (e) { | ||
console.error(e); | ||
process.exit(1); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters