fix(main): cap _jobLogCollector at 1000 jobs (FIFO eviction)

The per-job log collector was only cleared at start-upload — across a
long session with many add-jobs-to-running-batch interactions (no new
start-upload), the Map grew unbounded. At ~5000 tracked jobs that's
1 MB × 5 = 5 MB+ of stale history hanging around in the main process,
bigger as ring buffers fill.

Add a cap: when a new jobId would push size past 1000, evict the
oldest entry (Map iteration order is insertion order per spec). 1000
× 200 entries/job × ~100 B/entry ≈ 20 MB worst case, properly bounded
no matter how long the session runs. Per-job ring buffer (200 entries)
unchanged; only the count of tracked jobs is now capped.

The "Log anzeigen" modal still works for any job in the most-recent
1000 — older jobs return an empty array, which the renderer already
displays as "Keine Log-Einträge".
This commit is contained in:
Administrator 2026-04-28 04:09:27 +02:00
parent 0b306221d4
commit 4575b5ac26
2 changed files with 15 additions and 4 deletions

15
main.js
View File

@ -32,10 +32,23 @@ const _sessionAccountOverrides = new Map(); // hoster -> account object
// grepping account-rotation.log. Ring buffer per job keeps memory bounded.
const _jobLogCollector = new Map(); // jobId -> Array<entry>
const _MAX_LOG_ENTRIES_PER_JOB = 200;
// Cap the total number of jobs we keep history for — without this the Map
// keeps growing across batch-done boundaries (only start-upload clears it).
// 1000 jobs × 200 entries × ~100 bytes ≈ 20 MB worst case, bounded.
const _MAX_TRACKED_JOBS = 1000;
function _appendJobLog(jobId, entry) {
if (!jobId) return;
let arr = _jobLogCollector.get(jobId);
if (!arr) { arr = []; _jobLogCollector.set(jobId, arr); }
if (!arr) {
arr = [];
_jobLogCollector.set(jobId, arr);
// Evict oldest tracked job (insertion order) once we're past the cap.
// Map iteration is insertion-ordered in spec, so .keys().next() is FIFO.
if (_jobLogCollector.size > _MAX_TRACKED_JOBS) {
const oldestId = _jobLogCollector.keys().next().value;
if (oldestId !== undefined) _jobLogCollector.delete(oldestId);
}
}
if (arr.length >= _MAX_LOG_ENTRIES_PER_JOB) arr.shift();
arr.push(entry);
}

View File

@ -4,12 +4,10 @@
- ✅ 3.3.0 — Performance-Fixes (queue-cap, sort-throttle, history-delegation, recent-cap) + Log-Recovery
- ✅ 3.3.1 — `removeFromQueueOnDone` coalesced via microtask (kein O(N²) mehr bei done-Bursts)
- ✅ 3.3.2 — `fileuploader.log` Auto-Rotation bei 50 MB (max 3 Backups: .1 .2 .3)
- ✅ 3.3.3 — `_jobLogCollector` Cap auf 1000 tracked jobs (FIFO-eviction beim Überschreiten)
## Open items (priorisiert)
### Stabilität
- [ ] **`_jobLogCollector`** (main.js) — wird nur bei start-upload geleert, nicht bei batch-done. Bei vielen Batches ohne neuen start-upload wächst es. Cleanup bei batch-done für jobs die nicht mehr in queueJobs sind.
### Performance
- [ ] **`applyQueueSelectionClasses`** (renderer/app.js:891) — `tbody.querySelectorAll` bei jedem Klick. Bei 5000-Jobs-Queue O(N) per click. Cache last rendered range.