From d280765feb0332db22d16bc127e30304ed9b8a31 Mon Sep 17 00:00:00 2001 From: Administrator Date: Sun, 7 Jun 2026 20:40:55 +0200 Subject: [PATCH] =?UTF-8?q?fix(perf):=20freeze=20on=20Start=20with=202000+?= =?UTF-8?q?=20jobs=20=E2=80=94=20gate=20probe=20+=20rot-log=20behind=20sem?= =?UTF-8?q?aphore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/upload-manager.js | 26 +++++++++++++++----------- main.js | 11 ++++++++++- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/lib/upload-manager.js b/lib/upload-manager.js index 5e8102f..516c15d 100644 --- a/lib/upload-manager.js +++ b/lib/upload-manager.js @@ -9,7 +9,7 @@ const DoodstreamUploader = require('./doodstream-upload'); const ClouddropUploader = require('./clouddrop-upload'); const Semaphore = require('./semaphore'); const Throttle = require('./throttle'); -const { probeFileHead, summarizeFileStat } = require('./file-probe'); +const { probeFileHead } = require('./file-probe'); const DEFAULT_SETTINGS = { retries: 3, @@ -435,21 +435,25 @@ class UploadManager extends EventEmitter { maxAttempts }); - const fileStat = summarizeFileStat(task.file); - const fileProbe = await probeFileHead(task.file, 64).catch((err) => ({ ok: false, error: err.message, kind: 'unreadable' })); - this._rotLog('upload-start', { - jobId, hoster: task.hoster, accountId: task.accountId, fileName, - fileSize: fileStat.size, fileMtime: fileStat.mtime, - detectedKind: fileProbe && fileProbe.kind ? fileProbe.kind : 'unknown', - isVideoLike: !!(fileProbe && fileProbe.isVideoLike), - headHex: fileProbe && fileProbe.headHex ? fileProbe.headHex.slice(0, 32) : null - }); - // Acquire hoster semaphore first so jobs waiting for a hoster slot // don't waste global slots (prevents underutilization) await hosterSemaphore.acquire(signal); hosterSlotAcquired = true; + let fileProbe = null; + try { + fileProbe = await probeFileHead(task.file, 64); + } catch (err) { + fileProbe = { ok: false, error: err && err.message, kind: 'unreadable' }; + } + this._rotLog('upload-start', { + jobId, hoster: task.hoster, accountId: task.accountId, fileName, + fileSize, + detectedKind: fileProbe && fileProbe.kind ? fileProbe.kind : 'unknown', + isVideoLike: !!(fileProbe && fileProbe.isVideoLike), + headHex: fileProbe && fileProbe.headHex ? fileProbe.headHex.slice(0, 32) : null + }); + if (globalSemaphore) { await globalSemaphore.acquire(signal); globalSlotAcquired = true; diff --git a/main.js b/main.js index 5b879ba..c4ac6e3 100644 --- a/main.js +++ b/main.js @@ -1445,6 +1445,15 @@ ipcMain.handle('start-upload', (_event, payload) => { } }); + const ROT_LOG_RENDERER_EVENTS = new Set([ + 'switchAccount', + 'pre-job-swap', + 'try-alternate-after-fail', + 'mark-failed', + 'rotation-end', + 'doodstream-via-api', + 'doodstream-via-web' + ]); uploadManager.on('rot-log', (entry) => { const { ts, event, ...rest } = entry; const pairs = Object.entries(rest) @@ -1454,7 +1463,7 @@ ipcMain.handle('start-upload', (_event, payload) => { if (entry.jobId) { _appendJobLog(entry.jobId, { ts: ts || Date.now(), kind: 'rot', event, ...rest }); } - if (mainWindow && !mainWindow.isDestroyed()) { + if (mainWindow && !mainWindow.isDestroyed() && ROT_LOG_RENDERER_EVENTS.has(event)) { mainWindow.webContents.send('account-rotation-log', entry); } });