mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-09-19 20:51:19 +02: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;
|
||||
|
||||
void request.finally(() => delete activeRequestPromises[key as string]);
|
||||
void request.finally(() => {
|
||||
delete activeRequestPromises[key as string];
|
||||
|
||||
resetKeys.delete(key);
|
||||
});
|
||||
|
||||
return request;
|
||||
};
|
||||
|
@ -202,11 +206,12 @@ if (config.redis?.enabled) {
|
|||
|
||||
const ttl = client.ttl.bind(client);
|
||||
exportClient.ttl = async (key) => {
|
||||
if (cache && cacheClient && ttlCache.has(key)) {
|
||||
const ttlResult = cache && cacheClient && ttlCache.get(key);
|
||||
if (ttlResult != null) {
|
||||
// Trigger usage of cache
|
||||
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 {
|
||||
const result = await ttl(createKeyName(key));
|
||||
if (ttlCache) ttlCache.set(key, Math.floor(Date.now() / 1000) - (config.redis?.expiryTime - result));
|
||||
|
|
Loading…
Reference in a new issue