Rewrite ban insert query to use one insert rather than one per ban

Fixes #21
master
Dessa Simpson 2020-10-25 21:31:18 -07:00
parent 36d3871bdc
commit b479cd2948
2 changed files with 18 additions and 8 deletions

View File

@ -313,10 +313,24 @@ async function processBannedUsers() {
dbconn.query("DELETE FROM bans");
log(LogLevel.DEBUG,"Ban list:")
log(LogLevel.DEBUG,JSON.stringify(response.data,null,2));
var insertBanQuery = "INSERT INTO bans (userid) VALUES ";
var banRow = 0;
var bansArray: number[] = [];
for (var ban of response.data) {
if (ban.expires_at == '') dbconn.query(Object.assign(queries.insertBan,{ values: [ban.user_id] }))
if (ban.expires_at == '') {
banRow++;
insertBanQuery += `($${banRow}), `;
bansArray.push(ban.user_id as number);
}
}
db.query("CALL update_scores()");
var banQueryConfig = {
text: insertBanQuery.slice(0,-2), // Cut last `, ` off of the end
values: bansArray
};
log(LogLevel.DEBUG,"banQueryConfig object:")
log(LogLevel.DEBUG,JSON.stringify(banQueryConfig,null,2))
dbconn.query(banQueryConfig);
dbconn.query("CALL update_scores()");
await dbconn.query('COMMIT');
} catch (e) {
await dbconn.query('ROLLBACK');
@ -326,7 +340,8 @@ async function processBannedUsers() {
setTimeout(processBannedUsers,3600000+Math.floor(Math.random()*900000)) // Run every 1-1.25 hours to balance load
}
setTimeout(processBannedUsers,3600000+Math.floor(Math.random()*900000)) // Run every 1-1.25 hours to balance load
//setTimeout(processBannedUsers,3600000+Math.floor(Math.random()*900000)) // Run every 1-1.25 hours to balance load
processBannedUsers();
app.listen(config.port, () => {
console.log(`Listening on port ${config.port}`);

View File

@ -10,11 +10,6 @@ export const checkBan = {
text: "SELECT userid FROM bans WHERE userid = $1"
}
export const insertBan = {
name: "insertBan",
text: "INSERT INTO bans (userid) VALUES ($1)"
}
// Streamer-related queries
export const getStreamerId = {
name: "getStreamerId",