Repository navigation
fix(download): 上报当前下载速度而不是整段平均速度 - #88
Merged
std-microblock merged 1 commit intoOct 13, 2026
Merged
Conversation
下载速度一直按「已下载 / 从开始到现在的秒数」上报,也就是整段下载的平均值: 镜像中途变慢或卡住时,界面上的速度只会一路平滑下滑(用户看到「越下越慢」而不是 「卡住了」),重试等待期间数字也完全不动。单线程路径还只在进度前进 0.1% 时才上报, 卡住时干脆一直显示上一次的速度。 - 新增 SpeedMeter:按最近 3 秒的窗口算当前速度,刚开始窗口没铺满时退回整段平均。 - 单线程路径也按 200ms 的节奏上报(与多线程路径一致),卡住时速度会掉到 0。 - 新增 2 个单测覆盖窗口与「不再被历史高速率拉高」。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
群里的报告(Celeste Coders):下载 Mod 时「偶发下载速度越来越慢」。查下来有两半:
celeste-mirror-cdn-2.wegfan.com)速度可以差几十倍、部分对象不支持 Range、缺文件还返回 200 + JSON。这些不是本仓库能修的。根因(客户端那半)
前端原样显示这个数字(
DownloadList.tsx:22formatSpeed、:168/:273),并没有「平均」字样。实测:同一台 CDN、同一个 URL(本机直连,不走代理)
https://celeste.weg.fan/api/v2/download/gamebanana-files/831746(Mt Everest,17,488,764 字节)连续下 3 次:把上面这一条真实的慢速轨迹喂给两种算法:
旧算法一路从 0.24 掉到 0.16 再慢慢爬,看着就是「越来越慢」;新算法从一开始就如实报 0.13 MB/s、镜像恢复后立刻升到 1.18 MB/s。
改动
SpeedMeter(ureq.rs):按最近 3 秒的采样窗口算速度,下载刚开始窗口没铺满时退回整段平均;窗口外只保留一个采样点,避免采样间隔过短导致数字乱跳。report_progress不再自己算速度,改为接收调用方算好的数值。PROGRESS_INTERVAL(200ms,与多线程路径一致)上报,不再只在进度 +0.1% 时才报 —— 卡住时速度会掉到 0,而不是停在上一次的数字。没有改网络行为:8 线程分段、暂停、重试、Range 探测都没动(和 #84 / #85 / #87 不重叠)。
验证
cd src-tauri && cargo test --lib→ 109 passed; 0 failed(新增 2 个:窗口不丢旧采样点、卡顿后不再被历史高速率拉高)。cargo fmt --all -- --check通过。顺带查到的镜像侧事实(不在本 PR 范围,供参考)
gamebanana-files/1845372:Range: bytes=0-0返回 200 + 整个 9,109,998 字节(重复 2 次一致)→ CeleMod 的probe_range判定不支持分段,回退单连接(ureq.rs:346、:354)gamebanana-files/invalid→HTTP 200、content-type: application/json、54 字节{"data":null,"code":10002,"message":"文件未找到"};客户端会把它当成一次成功的 HTTP 下载,直到 zip 校验才失败celeste-mirror-cdn.wegfan.com证书过期CN=wegfan.cn, notAfter=Sep 10 23:59:59 2026 GMT(所以 20fc093 撤掉了强制改写节点那套)报告来源:Celeste Coders 群友(非开发者);暂停那条是已知问题,对应 PR #85。