mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 01:02:30 +01:00
One less call when dealing with lru cache for ttl result and ensure reset keys cleared
This commit is contained in:
parent
17059fdbe6
commit
8ba68e1b4c
1 changed files with 8 additions and 3 deletions
|
@ -154,7 +154,11 @@ if (config.redis?.enabled) {
|
||||||
|
|
||||||
activeRequestPromises[key as string] = request;
|
activeRequestPromises[key as string] = request;
|
||||||
|
|
||||||
void request.finally(() => delete activeRequestPromises[key as string]);
|
void request.finally(() => {
|
||||||
|
delete activeRequestPromises[key as string];
|
||||||
|
|
||||||
|
resetKeys.delete(key);
|
||||||
|
});
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
};
|
};
|
||||||
|
@ -202,11 +206,12 @@ if (config.redis?.enabled) {
|
||||||
|
|
||||||
const ttl = client.ttl.bind(client);
|
const ttl = client.ttl.bind(client);
|
||||||
exportClient.ttl = async (key) => {
|
exportClient.ttl = async (key) => {
|
||||||
if (cache && cacheClient && ttlCache.has(key)) {
|
const ttlResult = cache && cacheClient && ttlCache.get(key);
|
||||||
|
if (ttlResult != null) {
|
||||||
// Trigger usage of cache
|
// Trigger usage of cache
|
||||||
cache.get(key);
|
cache.get(key);
|
||||||
|
|
||||||
return ttlCache.get(key) + config.redis?.expiryTime - Math.floor(Date.now() / 1000);
|
return ttlResult + config.redis?.expiryTime - Math.floor(Date.now() / 1000);
|
||||||
} else {
|
} else {
|
||||||
const result = await ttl(createKeyName(key));
|
const result = await ttl(createKeyName(key));
|
||||||
if (ttlCache) ttlCache.set(key, Math.floor(Date.now() / 1000) - (config.redis?.expiryTime - result));
|
if (ttlCache) ttlCache.set(key, Math.floor(Date.now() / 1000) - (config.redis?.expiryTime - result));
|
||||||
|
|
Loading…
Reference in a new issue