From da8fea785c79b34ea3fb5a750b58f518846f433f Mon Sep 17 00:00:00 2001 From: HF Date: Mon, 5 Sep 2022 13:28:44 +0200 Subject: [PATCH] cache none-returned proxycheck requests for an hour to not flood ourselves --- src/core/isAllowed.js | 5 +---- src/data/redis/isAllowedCache.js | 3 ++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/core/isAllowed.js b/src/core/isAllowed.js index 4357a53..89e259a 100644 --- a/src/core/isAllowed.js +++ b/src/core/isAllowed.js @@ -63,13 +63,10 @@ async function withoutCache(f, ip) { status = res.status; allowed = res.allowed; pcheck = res.pcheck; - if (status === -2) { - throw new Error('Proxycheck request did not return yet'); - } } - cacheAllowed(ipKey, status); whoisRet = await whois(ip); } finally { + await cacheAllowed(ipKey, status); await saveIPInfo(ipKey, whoisRet || {}, status, pcheck); } diff --git a/src/data/redis/isAllowedCache.js b/src/data/redis/isAllowedCache.js index a5378c3..e27edd9 100644 --- a/src/data/redis/isAllowedCache.js +++ b/src/data/redis/isAllowedCache.js @@ -10,8 +10,9 @@ const CACHE_DURATION = 14 * 24 * 3600; export function cacheAllowed(ip, status) { const key = `${PREFIX}:${ip}`; + const expires = (status !== -2) ? CACHE_DURATION : 3600; return client.set(key, status, { - EX: CACHE_DURATION, + EX: expires, }); }