mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
try use p-limit instead of bottleneck
This commit is contained in:
@@ -10,6 +10,7 @@ import applyFilters from './lib/filter.js';
|
|||||||
import { applyMochs, getMochCatalog, getMochItemMeta } from './moch/moch.js';
|
import { applyMochs, getMochCatalog, getMochItemMeta } from './moch/moch.js';
|
||||||
import StaticLinks from './moch/static.js';
|
import StaticLinks from './moch/static.js';
|
||||||
import { createNamedQueue } from "./lib/namedQueue.js";
|
import { createNamedQueue } from "./lib/namedQueue.js";
|
||||||
|
import pLimit from "p-limit";
|
||||||
|
|
||||||
const CACHE_MAX_AGE = parseInt(process.env.CACHE_MAX_AGE) || 60 * 60; // 1 hour in seconds
|
const CACHE_MAX_AGE = parseInt(process.env.CACHE_MAX_AGE) || 60 * 60; // 1 hour in seconds
|
||||||
const CACHE_MAX_AGE_EMPTY = 60; // 60 seconds
|
const CACHE_MAX_AGE_EMPTY = 60; // 60 seconds
|
||||||
@@ -24,6 +25,7 @@ const limiter = new Bottleneck({
|
|||||||
highWater: process.env.LIMIT_QUEUE_SIZE || 100,
|
highWater: process.env.LIMIT_QUEUE_SIZE || 100,
|
||||||
strategy: Bottleneck.strategy.OVERFLOW
|
strategy: Bottleneck.strategy.OVERFLOW
|
||||||
});
|
});
|
||||||
|
const newLimiter = pLimit(40)
|
||||||
const limiterOptions = { expiration: 2 * 60 * 1000 }
|
const limiterOptions = { expiration: 2 * 60 * 1000 }
|
||||||
|
|
||||||
builder.defineStreamHandler((args) => {
|
builder.defineStreamHandler((args) => {
|
||||||
@@ -69,14 +71,14 @@ builder.defineMetaHandler((args) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
async function resolveStreams(args) {
|
async function resolveStreams(args) {
|
||||||
return cacheWrapStream(args.id, () => limiter.schedule(limiterOptions, () => streamHandler(args)
|
return cacheWrapStream(args.id, () => newLimiter(() => 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)))));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function streamHandler(args) {
|
async function streamHandler(args) {
|
||||||
console.log(`Current stats: `, limiter.counts())
|
console.log(`Pending count: ${newLimiter.pendingCount}, active count: ${newLimiter.activeCount}`, )
|
||||||
if (args.type === Type.MOVIE) {
|
if (args.type === Type.MOVIE) {
|
||||||
return movieRecordsHandler(args);
|
return movieRecordsHandler(args);
|
||||||
} else if (args.type === Type.SERIES) {
|
} else if (args.type === Type.SERIES) {
|
||||||
|
|||||||
26
addon/package-lock.json
generated
26
addon/package-lock.json
generated
@@ -22,6 +22,7 @@
|
|||||||
"name-to-imdb": "^3.0.4",
|
"name-to-imdb": "^3.0.4",
|
||||||
"named-queue": "^2.2.1",
|
"named-queue": "^2.2.1",
|
||||||
"offcloud-api": "^1.0.2",
|
"offcloud-api": "^1.0.2",
|
||||||
|
"p-limit": "^5.0.0",
|
||||||
"parse-torrent-title": "git://github.com/TheBeastLT/parse-torrent-title.git#022408972c2a040f846331a912a6a8487746a654",
|
"parse-torrent-title": "git://github.com/TheBeastLT/parse-torrent-title.git#022408972c2a040f846331a912a6a8487746a654",
|
||||||
"pg": "^8.10.0",
|
"pg": "^8.10.0",
|
||||||
"premiumize-api": "^1.0.3",
|
"premiumize-api": "^1.0.3",
|
||||||
@@ -1428,6 +1429,20 @@
|
|||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/p-limit": {
|
||||||
|
"version": "5.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-5.0.0.tgz",
|
||||||
|
"integrity": "sha512-/Eaoq+QyLSiXQ4lyYV23f14mZRQcXnxfHrN0vCai+ak9G0pp9iEQukIIZq5NccEvwRB8PUnZT0KsOoDCINS1qQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"yocto-queue": "^1.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/packet-reader": {
|
"node_modules/packet-reader": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/packet-reader/-/packet-reader-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/packet-reader/-/packet-reader-1.0.0.tgz",
|
||||||
@@ -2499,6 +2514,17 @@
|
|||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
|
||||||
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
|
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
|
||||||
|
},
|
||||||
|
"node_modules/yocto-queue": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12.20"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
"name-to-imdb": "^3.0.4",
|
"name-to-imdb": "^3.0.4",
|
||||||
"named-queue": "^2.2.1",
|
"named-queue": "^2.2.1",
|
||||||
"offcloud-api": "^1.0.2",
|
"offcloud-api": "^1.0.2",
|
||||||
|
"p-limit": "^5.0.0",
|
||||||
"parse-torrent-title": "git://github.com/TheBeastLT/parse-torrent-title.git#022408972c2a040f846331a912a6a8487746a654",
|
"parse-torrent-title": "git://github.com/TheBeastLT/parse-torrent-title.git#022408972c2a040f846331a912a6a8487746a654",
|
||||||
"pg": "^8.10.0",
|
"pg": "^8.10.0",
|
||||||
"premiumize-api": "^1.0.3",
|
"premiumize-api": "^1.0.3",
|
||||||
|
|||||||
Reference in New Issue
Block a user