diff --git a/nginx/proxy.conf b/nginx/proxy.conf index a3d30f3..82310bb 100644 --- a/nginx/proxy.conf +++ b/nginx/proxy.conf @@ -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; \ No newline at end of file +proxy_http_version 1.1; diff --git a/src/utils/redis.ts b/src/utils/redis.ts index 6083f3d..7faefe6 100644 --- a/src/utils/redis.ts +++ b/src/utils/redis.ts @@ -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))); diff --git a/src/utils/reputation.ts b/src/utils/reputation.ts index 777d65b..80d3eef 100644 --- a/src/utils/reputation.ts +++ b/src/utils/reputation.ts @@ -20,8 +20,8 @@ export async function getReputation(userID: UserID): Promise { // 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)