mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 09:07:47 +01:00
Move default hash times to var
This commit is contained in:
parent
5a69de730c
commit
8d533d0e94
1 changed files with 6 additions and 3 deletions
|
@ -4,8 +4,11 @@ import { HashedValue } from "../types/hash.model";
|
|||
import { Logger } from "../utils/logger";
|
||||
import { getHash } from "../utils/getHash";
|
||||
|
||||
export async function getHashCache<T extends string>(value: T, times = 5000): Promise<T & HashedValue> {
|
||||
if (times === 5000) {
|
||||
const defaultedHashTimes = 5000;
|
||||
const cachedHashTimes = defaultedHashTimes - 1;
|
||||
|
||||
export async function getHashCache<T extends string>(value: T, times = defaultedHashTimes): Promise<T & HashedValue> {
|
||||
if (times === defaultedHashTimes) {
|
||||
const hashKey = getHash(value, 1);
|
||||
const result: HashedValue = await getFromRedis(hashKey);
|
||||
return result as T & HashedValue;
|
||||
|
@ -25,7 +28,7 @@ async function getFromRedis<T extends string>(key: HashedValue): Promise<T & Has
|
|||
// If all else, continue on hashing
|
||||
}
|
||||
}
|
||||
const data = getHash(key, 5000-1);
|
||||
const data = getHash(key, cachedHashTimes);
|
||||
|
||||
redis.setAsync(key, data);
|
||||
return data as T & HashedValue;
|
||||
|
|
Loading…
Reference in a new issue