mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-12 14:37:17 +03:00
@@ -4,6 +4,8 @@ import { skipSegmentsHashKey, skipSegmentsKey, reputationKey, ratingHashKey, ski
|
|||||||
import { Service, VideoID, VideoIDHash } from "../types/segments.model";
|
import { Service, VideoID, VideoIDHash } from "../types/segments.model";
|
||||||
import { Feature, HashedUserID, UserID } from "../types/user.model";
|
import { Feature, HashedUserID, UserID } from "../types/user.model";
|
||||||
|
|
||||||
|
const expiryTime = 2 * 60 * 60;
|
||||||
|
|
||||||
async function get<T>(fetchFromDB: () => Promise<T>, key: string): Promise<T> {
|
async function get<T>(fetchFromDB: () => Promise<T>, key: string): Promise<T> {
|
||||||
try {
|
try {
|
||||||
const reply = await redis.get(key);
|
const reply = await redis.get(key);
|
||||||
@@ -16,7 +18,7 @@ async function get<T>(fetchFromDB: () => Promise<T>, key: string): Promise<T> {
|
|||||||
|
|
||||||
const data = await fetchFromDB();
|
const data = await fetchFromDB();
|
||||||
|
|
||||||
redis.set(key, JSON.stringify(data)).catch((err) => Logger.error(err));
|
redis.setEx(key, expiryTime, JSON.stringify(data)).catch((err) => Logger.error(err));
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@@ -67,7 +69,7 @@ async function getAndSplit<T, U extends string>(fetchFromDB: (values: U[]) => Pr
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const key in newResults) {
|
for (const key in newResults) {
|
||||||
redis.set(key, JSON.stringify(newResults[key])).catch((err) => Logger.error(err));
|
redis.setEx(key, expiryTime, JSON.stringify(newResults[key])).catch((err) => Logger.error(err));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user