mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 01:02:30 +01:00
Stop spamming redis if it slows down
This commit is contained in:
parent
96db571a5e
commit
571230db56
3 changed files with 9 additions and 1 deletions
|
@ -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) => {
|
||||
|
|
Loading…
Reference in a new issue