From 9df7979110fcc5dab095e6f5d08e81f24b0a21d4 Mon Sep 17 00:00:00 2001 From: ArielLeyva Date: Wed, 24 Sep 2025 03:36:22 -0400 Subject: [PATCH] fix(upload): throttle upload speed calculation to 100ms to avoid Infinity MB/s --- frontend/src/components/prompts/UploadFiles.vue | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/prompts/UploadFiles.vue b/frontend/src/components/prompts/UploadFiles.vue index 883fffe3..f2336375 100644 --- a/frontend/src/components/prompts/UploadFiles.vue +++ b/frontend/src/components/prompts/UploadFiles.vue @@ -100,6 +100,18 @@ const speedMbytes = computed(() => byteToMbyte(speed.value)); let lastSpeedUpdate: number = 0; let recentSpeeds: number[] = []; +let lastThrottleTime = 0; + +const throttledCalcullateSpeed = (sentBytes: number, oldSentBytes: number) => { + const now = Date.now(); + if (now - lastThrottleTime < 100) { + return; + } + + lastThrottleTime = now; + calculateSpeed(sentBytes, oldSentBytes); +}; + const calculateSpeed = (sentBytes: number, oldSentBytes: number) => { // Reset the state when the uploads batch is complete if (sentBytes === 0) { @@ -149,7 +161,7 @@ const calculateEta = () => { eta.value = remainingSize / speedBytesPerSecond; }; -watch(sentBytes, calculateSpeed); +watch(sentBytes, throttledCalcullateSpeed); watch(totalBytes, (totalBytes, oldTotalBytes) => { if (oldTotalBytes !== 0) {