This commit is contained in:
Ajay Ramachandran 2022-03-07 18:40:17 +01:00
commit 0bb6d29932
3 changed files with 12 additions and 5 deletions

View file

@ -7,6 +7,6 @@ client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 5s;
#proxy_send_timeout 10;
proxy_read_timeout 10s;
proxy_read_timeout 6s;
proxy_buffers 32 4k;
proxy_http_version 1.1;
proxy_http_version 1.1;

View file

@ -33,7 +33,14 @@ if (config.redis) {
const client = redis.createClient(config.redis);
exportObject = client;
exportObject.getAsync = (key) => new Promise((resolve) => client.get(key, (err, reply) => resolve({ err, reply })));
const timeoutDuration = 200;
exportObject.getAsync = (key) => new Promise((resolve) => {
const timeout = setTimeout(() => resolve({ err: null, reply: undefined }), timeoutDuration);
client.get(key, (err, reply) => {
clearTimeout(timeout);
resolve({ err, reply });
});
});
exportObject.setAsync = (key, value) => new Promise((resolve) => client.set(key, value, (err, reply) => resolve({ err, reply })));
exportObject.setAsyncEx = (key, value, seconds) => new Promise((resolve) => client.setex(key, seconds, value, (err, reply) => resolve({ err, reply })));
exportObject.delAsync = (...keys) => new Promise((resolve) => client.del(keys, (err) => resolve(err)));

View file

@ -20,8 +20,8 @@ export async function getReputation(userID: UserID): Promise<number> {
// 1596240000000 is August 1st 2020, a little after auto upvote was disabled
const fetchFromDB = () => db.prepare("get",
`SELECT COUNT(*) AS "totalSubmissions",
SUM(CASE WHEN "votes" < 0 THEN 1 ELSE 0 END) AS "downvotedSubmissions",
SUM(CASE WHEN "votes" < 0 AND "videoID" NOT IN
SUM(CASE WHEN "votes" < 0 AND "views" > 5 THEN 1 ELSE 0 END) AS "downvotedSubmissions",
SUM(CASE WHEN "votes" < 0 AND "views" > 5 AND "videoID" NOT IN
(SELECT b."videoID" FROM "sponsorTimes" as b
WHERE b."userID" = ?
AND b."votes" > 0 AND b."category" = "a"."category" AND b."videoID" = "a"."videoID" LIMIT 1)