fix(debrid): limit torbox magnet checks to 2 per user at any given time#729
fix(debrid): limit torbox magnet checks to 2 per user at any given time#729webstreamr wants to merge 1 commit intoViren070:mainfrom
Conversation
WalkthroughAdds per-token concurrency limiting for magnet checks in TorboxDebridService by introducing an LRU-backed cache of limiter functions and wiring checkMagnets to run via a per-token limiter. Changes
Sequence Diagram(s)sequenceDiagram
rect rgba(200,200,255,0.5)
participant Caller
participant TorboxDebridService
participant LRUCache
participant StremThruInterface
end
Caller->>TorboxDebridService: checkMagnets(token, magnets)
TorboxDebridService->>LRUCache: get or create limiter for token
LRUCache-->>TorboxDebridService: limiter(function)
TorboxDebridService->>limiter: run(() => stremthru.checkMagnets(magnets))
limiter->>StremThruInterface: stremthru.checkMagnets(magnets)
StremThruInterface-->>limiter: results
limiter-->>TorboxDebridService: results
TorboxDebridService-->>Caller: results
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Comment |
c9604d2 to
d0d9463
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@package.json`:
- Around line 34-38: The core package is missing a direct dependency on
lru-cache even though packages/core/src/debrid/torbox.ts imports it; add
"lru-cache": "^11.2.6" to the dependencies object in packages/core/package.json
so the core package declares and installs this runtime dependency explicitly,
then run install to update the lockfiles.
🧹 Nitpick comments (1)
packages/core/src/debrid/torbox.ts (1)
154-161: Limiter is process‑local; consider cross‑instance coordination if you scale out.This cache lives in‑process, so multiple server instances can still exceed 2 concurrent checks per token. If you run more than one Node process, consider a shared semaphore/queue (e.g., Redis) to enforce a global limit.
d0d9463 to
c3dcb52
Compare
c3dcb52 to
d62a571
Compare
| return this.stremthru.checkMagnets(magnets, sid); | ||
| let limiter = TorboxDebridService.checkMagnetsLimiters.get(this.token); | ||
| if (!limiter) { | ||
| limiter = pLimit(2); |
There was a problem hiding this comment.
not sure what a good number here is tbh and it's a bit hard to test right now because some systems have intermittent issues. maybe it should just be 1 🤷♂️
|
TorBox raised limits to 300/s and ST switched to non-batched post requests. This dirty workaround is not needed for now. |
this is a simple and stupid workaround to avoid hitting the 5/s limits with the current aiostreams design. it seems to work quite well on my local system and should still leave room for wrapped add-ons doing their own availability checks.
in case this gets merged - something similar will be needed for nzb checks too I suppose. I only have a single indexer and don't experience problems there though.
Summary by CodeRabbit
Dependencies
Performance Improvements