mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-26 17:38:28 +03:00
Move default hash times to var
This commit is contained in:
@@ -4,8 +4,11 @@ import { HashedValue } from "../types/hash.model";
|
|||||||
import { Logger } from "../utils/logger";
|
import { Logger } from "../utils/logger";
|
||||||
import { getHash } from "../utils/getHash";
|
import { getHash } from "../utils/getHash";
|
||||||
|
|
||||||
export async function getHashCache<T extends string>(value: T, times = 5000): Promise<T & HashedValue> {
|
const defaultedHashTimes = 5000;
|
||||||
if (times === 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 hashKey = getHash(value, 1);
|
||||||
const result: HashedValue = await getFromRedis(hashKey);
|
const result: HashedValue = await getFromRedis(hashKey);
|
||||||
return result as T & HashedValue;
|
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
|
// If all else, continue on hashing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const data = getHash(key, 5000-1);
|
const data = getHash(key, cachedHashTimes);
|
||||||
|
|
||||||
redis.setAsync(key, data);
|
redis.setAsync(key, data);
|
||||||
return data as T & HashedValue;
|
return data as T & HashedValue;
|
||||||
|
|||||||
Reference in New Issue
Block a user