Make bans work properly

master
Dessa Simpson 2020-09-19 12:18:45 -07:00
parent 53da0eb687
commit 76aa7b3bc4
3 changed files with 21 additions and 6 deletions

View File

@ -1,3 +1,4 @@
CREATE TABLE bans ( CREATE TABLE bans (
userid integer userid integer,
PRIMARY KEY (userid)
) )

View File

@ -86,23 +86,35 @@ as in the case of no votes, user.* will be NULL.
*/ */
CREATE OR REPLACE VIEW vote_score_normal_vw AS CREATE OR REPLACE VIEW vote_score_normal_vw AS
SELECT requests.url,COUNT(votes.requesturl),(COUNT(votes.requesturl) * (SELECT normaluservotepoints FROM config)) AS votescore FROM requests SELECT requests.url,
COUNT(votes.requesturl) FILTER(WHERE bans.userid IS NULL),
(COUNT(votes.requesturl) FILTER(WHERE bans.userid IS NULL) * (SELECT normaluservotepoints FROM config)) AS votescore
FROM requests
LEFT JOIN votes ON votes.requesturl = requests.url LEFT JOIN votes ON votes.requesturl = requests.url
LEFT JOIN users on votes.userid = users.userid LEFT JOIN users on votes.userid = users.userid
WHERE COALESCE(users.isfollower,FALSE) = FALSE AND COALESCE(users.issubscriber,FALSE) = FALSE LEFT JOIN bans ON users.userid = bans.userid
WHERE COALESCE(users.isfollower,FALSE) = FALSE
AND COALESCE(users.issubscriber,FALSE) = FALSE
GROUP BY requests.url; GROUP BY requests.url;
CREATE OR REPLACE VIEW vote_score_follower_vw AS CREATE OR REPLACE VIEW vote_score_follower_vw AS
SELECT requests.url,COUNT(votes.requesturl),(COUNT(votes.requesturl) * (SELECT followervotepoints FROM config)) AS votescore FROM requests SELECT requests.url,
COUNT(votes.requesturl) FILTER(WHERE bans.userid IS NULL),
(COUNT(votes.requesturl) FILTER(WHERE bans.userid IS NULL) * (SELECT followervotepoints FROM config)) AS votescore
LEFT JOIN votes ON votes.requesturl = requests.url LEFT JOIN votes ON votes.requesturl = requests.url
LEFT JOIN users on votes.userid = users.userid LEFT JOIN users on votes.userid = users.userid
WHERE COALESCE(users.isfollower,FALSE) = TRUE AND COALESCE(users.issubscriber,FALSE) = FALSE LEFT JOIN bans ON users.userid = bans.userid
WHERE COALESCE(users.isfollower,FALSE) = TRUE
AND COALESCE(users.issubscriber,FALSE) = FALSE
GROUP BY requests.url; GROUP BY requests.url;
CREATE OR REPLACE VIEW vote_score_subscriber_vw AS CREATE OR REPLACE VIEW vote_score_subscriber_vw AS
SELECT requests.url,COUNT(votes.requesturl),(COUNT(votes.requesturl) * (SELECT subscribervotepoints FROM config)) AS votescore FROM requests SELECT requests.url,
COUNT(votes.requesturl) FILTER(WHERE bans.userid IS NULL),
(COUNT(votes.requesturl) FILTER(WHERE bans.userid IS NULL) * (SELECT subscribervotepoints FROM config)) AS votescore
LEFT JOIN votes ON votes.requesturl = requests.url LEFT JOIN votes ON votes.requesturl = requests.url
LEFT JOIN users on votes.userid = users.userid LEFT JOIN users on votes.userid = users.userid
LEFT JOIN bans ON users.userid = bans.userid
WHERE COALESCE(users.issubscriber,FALSE) = TRUE WHERE COALESCE(users.issubscriber,FALSE) = TRUE
GROUP BY requests.url; GROUP BY requests.url;

View File

@ -310,9 +310,11 @@ async function processBannedUsers() {
var dbconn = await db.connect(); var dbconn = await db.connect();
try { try {
await dbconn.query('BEGIN'); await dbconn.query('BEGIN');
db.query("DELETE FROM bans");
for (var ban of response.data) { for (var ban of response.data) {
if (ban.expires_at == '') dbconn.query(Object.assign(queries.insertBan,{ values: [ban.user_id] })) if (ban.expires_at == '') dbconn.query(Object.assign(queries.insertBan,{ values: [ban.user_id] }))
} }
db.query("CALL update_scores()");
await dbconn.query('COMMIT'); await dbconn.query('COMMIT');
} catch (e) { } catch (e) {
await dbconn.query('ROLLBACK'); await dbconn.query('ROLLBACK');