fix: remove unused peak speed update dispatch in DownloadGroup component

This commit is contained in:
Moyasee
2025-12-13 17:41:15 +02:00
parent 77b6f1b2ad
commit 67f863e0f3
2 changed files with 11 additions and 4 deletions

View File

@@ -30,6 +30,15 @@ export const downloadSlice = createSlice({
setLastPacket: (state, action: PayloadAction<DownloadProgress | null>) => {
state.lastPacket = action.payload;
if (!state.gameId && action.payload) state.gameId = action.payload.gameId;
// Track peak speed atomically when packet arrives
if (action.payload?.gameId && action.payload.downloadSpeed != null) {
const { gameId, downloadSpeed } = action.payload;
const currentPeak = state.peakSpeeds[gameId] || 0;
if (downloadSpeed > currentPeak) {
state.peakSpeeds[gameId] = downloadSpeed;
}
}
},
clearDownload: (state) => {
state.lastPacket = null;

View File

@@ -16,7 +16,7 @@ import {
useLibrary,
useDate,
} from "@renderer/hooks";
import { updatePeakSpeed, clearPeakSpeed } from "@renderer/features";
import { clearPeakSpeed } from "@renderer/features";
import "./download-group.scss";
import { useTranslation } from "react-i18next";
@@ -585,8 +585,6 @@ export function DownloadGroup({
const gameId = lastPacket.gameId;
const downloadSpeed = lastPacket.downloadSpeed;
dispatch(updatePeakSpeed({ gameId, speed: downloadSpeed }));
if (!speedHistoryRef.current[gameId]) {
speedHistoryRef.current[gameId] = [];
}
@@ -596,7 +594,7 @@ export function DownloadGroup({
if (speedHistoryRef.current[gameId].length > 120) {
speedHistoryRef.current[gameId].shift();
}
}, [lastPacket, dispatch]);
}, [lastPacket]);
useEffect(() => {
for (const game of library) {