fix(upload): throttle upload speed calculation to 100ms to avoid Infinity MB/s

This commit is contained in:
ArielLeyva 2025-09-24 03:36:22 -04:00 committed by Henrique Dias
parent b9787c78f3
commit 9df7979110
No known key found for this signature in database

View File

@ -100,6 +100,18 @@ const speedMbytes = computed(() => byteToMbyte(speed.value));
let lastSpeedUpdate: number = 0; let lastSpeedUpdate: number = 0;
let recentSpeeds: number[] = []; 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) => { const calculateSpeed = (sentBytes: number, oldSentBytes: number) => {
// Reset the state when the uploads batch is complete // Reset the state when the uploads batch is complete
if (sentBytes === 0) { if (sentBytes === 0) {
@ -149,7 +161,7 @@ const calculateEta = () => {
eta.value = remainingSize / speedBytesPerSecond; eta.value = remainingSize / speedBytesPerSecond;
}; };
watch(sentBytes, calculateSpeed); watch(sentBytes, throttledCalcullateSpeed);
watch(totalBytes, (totalBytes, oldTotalBytes) => { watch(totalBytes, (totalBytes, oldTotalBytes) => {
if (oldTotalBytes !== 0) { if (oldTotalBytes !== 0) {