From b9a8d49063f390cf08f29fd5c0772d92ae57e7b0 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Mon, 6 Jul 2026 00:09:39 +0200 Subject: [PATCH] Biometric time remaining accounting for skipped files. --- src/biometrics.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/biometrics.js b/src/biometrics.js index 313ee6a3..91d6845d 100644 --- a/src/biometrics.js +++ b/src/biometrics.js @@ -26,6 +26,7 @@ const humanConfig = { let humanInstance = null; const nsPerSec = 1e9; +const remainingTimeWindow = 30; // number of recent entries used to estimate time remaining async function getHumanInstance() { if (!humanInstance) { @@ -118,6 +119,7 @@ async function setBiometrics(actorIds, shouldUpdate = false, includePhotos = fal } const startTime = process.hrtime(); + const recentDurationsMs = []; const avatarSource = getAvatarSource(actorIds, includePhotos); @@ -142,6 +144,8 @@ async function setBiometrics(actorIds, shouldUpdate = false, includePhotos = fal return; } + const entryStartTime = process.hrtime(); + const biometrics = await getBiometrics(avatarEntry); if (!biometrics) { @@ -184,14 +188,20 @@ async function setBiometrics(actorIds, shouldUpdate = false, includePhotos = fal .onConflict(['media_id', 'face_index']) .ignore(); - const processed = avatarIndex + 1; - const [elapsedSec, elapsedNs] = process.hrtime(startTime); - const elapsedMs = (elapsedSec * nsPerSec + elapsedNs) / 1e6; - const avgMsPerEntry = elapsedMs / processed; - const remainingMs = avgMsPerEntry * (avatarEntries.length - processed); + const [entrySec, entryNs] = process.hrtime(entryStartTime); + const entryMs = (entrySec * nsPerSec + entryNs) / 1e6; + + recentDurationsMs.push(entryMs); + + if (recentDurationsMs.length > remainingTimeWindow) { + recentDurationsMs.shift(); + } + + const avgMsPerEntry = recentDurationsMs.reduce((sum, ms) => sum + ms, 0) / recentDurationsMs.length; + const remainingMs = avgMsPerEntry * (avatarEntries.length - (avatarIndex + 1)); const remainingMinutes = (remainingMs / 1000 / 60).toFixed(1); - logger.info(`Set biometrics for ${avatarEntry.media_id} (${processed}/${avatarEntries.length}, ~${remainingMinutes}m remaining)`); + logger.info(`Set biometrics for ${avatarEntry.media_id} (${avatarIndex + 1}/${avatarEntries.length}, ~${remainingMinutes}m remaining)`); }, Promise.resolve()); const diffTime = process.hrtime(startTime);