cache none-returned proxycheck requests for an hour to not flood

ourselves
This commit is contained in:
HF 2022-09-05 13:28:44 +02:00
parent efeed7994d
commit da8fea785c
2 changed files with 3 additions and 5 deletions

View File

@ -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);
}

View File

@ -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,
});
}