cache none-returned proxycheck requests for an hour to not flood
ourselves
This commit is contained in:
parent
efeed7994d
commit
da8fea785c
|
@ -63,13 +63,10 @@ async function withoutCache(f, ip) {
|
||||||
status = res.status;
|
status = res.status;
|
||||||
allowed = res.allowed;
|
allowed = res.allowed;
|
||||||
pcheck = res.pcheck;
|
pcheck = res.pcheck;
|
||||||
if (status === -2) {
|
|
||||||
throw new Error('Proxycheck request did not return yet');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
cacheAllowed(ipKey, status);
|
|
||||||
whoisRet = await whois(ip);
|
whoisRet = await whois(ip);
|
||||||
} finally {
|
} finally {
|
||||||
|
await cacheAllowed(ipKey, status);
|
||||||
await saveIPInfo(ipKey, whoisRet || {}, status, pcheck);
|
await saveIPInfo(ipKey, whoisRet || {}, status, pcheck);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,9 @@ const CACHE_DURATION = 14 * 24 * 3600;
|
||||||
|
|
||||||
export function cacheAllowed(ip, status) {
|
export function cacheAllowed(ip, status) {
|
||||||
const key = `${PREFIX}:${ip}`;
|
const key = `${PREFIX}:${ip}`;
|
||||||
|
const expires = (status !== -2) ? CACHE_DURATION : 3600;
|
||||||
return client.set(key, status, {
|
return client.set(key, status, {
|
||||||
EX: CACHE_DURATION,
|
EX: expires,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user