update proxycheck cache even on withoutCache request

This commit is contained in:
HF 2022-08-07 20:31:46 +02:00
parent a2147eef8c
commit 8f91b3c241
2 changed files with 4 additions and 6 deletions

View File

@ -70,6 +70,7 @@ async function withoutCache(f, ip) {
throw new Error('Proxycheck request did not return yet'); throw new Error('Proxycheck request did not return yet');
} }
} }
cacheAllowed(ipKey, status);
whoisRet = await whois(ip); whoisRet = await whois(ip);
} finally { } finally {
await saveIPInfo(ipKey, whoisRet || {}, status, pcheck); await saveIPInfo(ipKey, whoisRet || {}, status, pcheck);
@ -108,11 +109,8 @@ async function withCache(f, ip) {
if (checking.indexOf(ipKey) === -1) { if (checking.indexOf(ipKey) === -1) {
checking.push(ipKey); checking.push(ipKey);
withoutCache(f, ip) withoutCache(f, ip)
.then((result) => {
cacheAllowed(ipKey, result);
})
.catch((error) => { .catch((error) => {
logger.error('Error %s', error.message || error); logger.error('Error %s', error.message);
}) })
.finally(() => { .finally(() => {
const pos = checking.indexOf(ipKey); const pos = checking.indexOf(ipKey);

View File

@ -8,9 +8,9 @@ import client from './client';
const PREFIX = 'isal:'; const PREFIX = 'isal:';
const CACHE_DURATION = 14 * 24 * 3600; const CACHE_DURATION = 14 * 24 * 3600;
export function cacheAllowed(ip, allowed) { export function cacheAllowed(ip, status) {
const key = `${PREFIX}:${ip}`; const key = `${PREFIX}:${ip}`;
return client.set(key, allowed.status, { return client.set(key, status, {
EX: CACHE_DURATION, EX: CACHE_DURATION,
}); });
} }