From 8f91b3c241d6fb25a8682c05fb914033ea1d8110 Mon Sep 17 00:00:00 2001 From: HF Date: Sun, 7 Aug 2022 20:31:46 +0200 Subject: [PATCH] update proxycheck cache even on withoutCache request --- src/core/isAllowed.js | 6 ++---- src/data/redis/isAllowedCache.js | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/core/isAllowed.js b/src/core/isAllowed.js index 20bd9c8..fee68ea 100644 --- a/src/core/isAllowed.js +++ b/src/core/isAllowed.js @@ -70,6 +70,7 @@ async function withoutCache(f, ip) { throw new Error('Proxycheck request did not return yet'); } } + cacheAllowed(ipKey, status); whoisRet = await whois(ip); } finally { await saveIPInfo(ipKey, whoisRet || {}, status, pcheck); @@ -108,11 +109,8 @@ async function withCache(f, ip) { if (checking.indexOf(ipKey) === -1) { checking.push(ipKey); withoutCache(f, ip) - .then((result) => { - cacheAllowed(ipKey, result); - }) .catch((error) => { - logger.error('Error %s', error.message || error); + logger.error('Error %s', error.message); }) .finally(() => { const pos = checking.indexOf(ipKey); diff --git a/src/data/redis/isAllowedCache.js b/src/data/redis/isAllowedCache.js index 3ca5f0d..ebb971a 100644 --- a/src/data/redis/isAllowedCache.js +++ b/src/data/redis/isAllowedCache.js @@ -8,9 +8,9 @@ import client from './client'; const PREFIX = 'isal:'; const CACHE_DURATION = 14 * 24 * 3600; -export function cacheAllowed(ip, allowed) { +export function cacheAllowed(ip, status) { const key = `${PREFIX}:${ip}`; - return client.set(key, allowed.status, { + return client.set(key, status, { EX: CACHE_DURATION, }); }