mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-11 22:17:14 +03:00
Stop spamming redis if it slows down
This commit is contained in:
@@ -136,7 +136,8 @@ addDefaults(config, {
|
||||
},
|
||||
disableOfflineQueue: true,
|
||||
expiryTime: 24 * 60 * 60,
|
||||
getTimeout: 40
|
||||
getTimeout: 40,
|
||||
maxConnections: 15000
|
||||
},
|
||||
redisRead: {
|
||||
enabled: false,
|
||||
|
||||
@@ -5,6 +5,7 @@ interface RedisConfig extends redis.RedisClientOptions {
|
||||
enabled: boolean;
|
||||
expiryTime: number;
|
||||
getTimeout: number;
|
||||
maxConnections: number;
|
||||
}
|
||||
|
||||
interface RedisReadOnlyConfig extends redis.RedisClientOptions {
|
||||
|
||||
@@ -41,7 +41,13 @@ if (config.redis?.enabled) {
|
||||
const get = client.get.bind(client);
|
||||
const getRead = readClient?.get?.bind(readClient);
|
||||
exportClient.get = (key) => new Promise((resolve, reject) => {
|
||||
if (activeRequests > config.redis.maxConnections) {
|
||||
reject("Too many active requests");
|
||||
return;
|
||||
}
|
||||
|
||||
activeRequests++;
|
||||
|
||||
const timeout = config.redis.getTimeout ? setTimeout(() => reject(), config.redis.getTimeout) : null;
|
||||
const chosenGet = pickChoice(get, getRead);
|
||||
chosenGet(key).then((reply) => {
|
||||
|
||||
Reference in New Issue
Block a user