Limit visible AllDebrid start countdowns

This commit is contained in:
Sucukdeluxe
2026-03-08 21:47:11 +01:00
parent fdb575b0c1
commit 8b941a2777
2 changed files with 139 additions and 0 deletions
+40
View File
@@ -5541,6 +5541,35 @@ export class DownloadManager extends EventEmitter {
return provider;
}
private countVisiblePacedStarts(paceKey: string, now: number, excludeItemId?: string): number {
let count = 0;
for (const [itemId, reservedAt] of this.pacedStartReservationByItem.entries()) {
if (excludeItemId && itemId === excludeItemId) {
continue;
}
if (reservedAt <= now) {
continue;
}
const item = this.session.items[itemId];
if (!item) {
continue;
}
if (this.getPacedStartKeyForItem(item) !== paceKey) {
continue;
}
if (item.status !== "queued" && item.status !== "reconnect_wait") {
continue;
}
count += 1;
}
return count;
}
private getVisiblePacedStartBudget(): number {
const maxParallel = Math.max(1, Number(this.settings.maxParallel) || 1);
return Math.max(0, maxParallel - this.activeTasks.size);
}
private delayPacedStartForItem(item: DownloadItem, now: number): boolean {
const paceKey = this.getPacedStartKeyForItem(item);
if (!paceKey) {
@@ -5569,6 +5598,17 @@ export class DownloadManager extends EventEmitter {
return false;
}
const visibleBudget = this.getVisiblePacedStartBudget();
const visibleReservations = this.countVisiblePacedStarts(paceKey, now, item.id);
if (visibleBudget <= 0 || visibleReservations >= visibleBudget) {
this.pacedStartReservationByItem.delete(item.id);
if ((item.fullStatus || "").startsWith("AllDebrid Start in ")) {
item.fullStatus = "Wartet";
item.updatedAt = now;
}
return true;
}
const scheduledAt = Math.max(existingReadyAt, nextAllowedAt);
if (scheduledAt <= now) {
this.pacedStartReservationByItem.delete(item.id);