move limiter before mongo call

This commit is contained in:
TheBeastLT
2024-01-21 23:14:44 +02:00
parent 8a4eb4cdfe
commit 4ee220a1ad
2 changed files with 4 additions and 4 deletions

View File

@@ -18,8 +18,8 @@ const STALE_ERROR_AGE = 7 * 24 * 60 * 60; // 7 days
const builder = new addonBuilder(dummyManifest()); const builder = new addonBuilder(dummyManifest());
const limiter = new Bottleneck({ const limiter = new Bottleneck({
maxConcurrent: process.env.LIMIT_MAX_CONCURRENT || 200, maxConcurrent: process.env.LIMIT_MAX_CONCURRENT || 100,
highWater: process.env.LIMIT_QUEUE_SIZE || 220, highWater: process.env.LIMIT_QUEUE_SIZE || 120,
strategy: Bottleneck.strategy.OVERFLOW strategy: Bottleneck.strategy.OVERFLOW
}); });
const limiterOptions = { expiration: 2 * 60 * 1000 } const limiterOptions = { expiration: 2 * 60 * 1000 }
@@ -29,7 +29,7 @@ builder.defineStreamHandler((args) => {
return Promise.resolve({ streams: [] }); return Promise.resolve({ streams: [] });
} }
return cacheWrapStream(args.id, () => limiter.schedule(limiterOptions, () => streamHandler(args) return limiter.schedule(limiterOptions, () => cacheWrapStream(args.id, () => streamHandler(args)
.then(records => records .then(records => records
.sort((a, b) => b.torrent.seeders - a.torrent.seeders || b.torrent.uploadDate - a.torrent.uploadDate) .sort((a, b) => b.torrent.seeders - a.torrent.seeders || b.torrent.uploadDate - a.torrent.uploadDate)
.map(record => toStreamInfo(record))))) .map(record => toStreamInfo(record)))))

View File

@@ -29,7 +29,7 @@ function initiateRemoteCache() {
uri: MONGO_URI, uri: MONGO_URI,
options: { options: {
collection: 'torrentio_addon_collection', collection: 'torrentio_addon_collection',
socketTimeoutMS: 120000, socketTimeoutMS: 30000,
useNewUrlParser: true, useNewUrlParser: true,
useUnifiedTopology: false, useUnifiedTopology: false,
ttl: STREAM_EMPTY_TTL ttl: STREAM_EMPTY_TTL