From 44fa82214601d5aaf42103f188ad5ff3b5b2a59d Mon Sep 17 00:00:00 2001 From: xiyidaiwa Date: Mon, 10 Aug 2026 23:57:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8E=92=E8=A1=8C=E6=A6=9C=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E6=AF=94=E8=BE=83=E9=B2=81=E6=A3=92=E6=80=A7=20+=20?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E8=AE=A1=E6=95=B0=E8=AF=B7=E6=B1=82=E5=8F=96?= =?UTF-8?q?=E6=B6=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ranking.ts: topByUpdate 改用时戳数字比较,兼容后端不一致的日期格式 (如 2026-08-10 / 2026/08/10 / 带时分秒),无效日期兜底为 0 避免 NaN 乱序 - App.vue: fetchDownloadCount 的 fetch 加 rootAbortController.signal, 组件卸载时可取消未完成请求,避免内存泄漏 (注: 这两个真实缺陷由 PR 审查在错误 diff 下点名,本提交独立于 Erotica PR) --- src/App.vue | 1 + src/modules/ranking.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/App.vue b/src/App.vue index 362142b7..771da690 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1311,6 +1311,7 @@ const fetchDownloadCount = async (app: App): Promise => { try { const resp = await fetch( `${APM_STORE_BASE_URL}/${finalArch}/${app.category}/${app.pkgname}/download-times.txt`, + { signal: rootAbortController.signal }, ); if (!resp.ok) return 0; const text = (await resp.text()).trim(); diff --git a/src/modules/ranking.ts b/src/modules/ranking.ts index aa71db47..197bee53 100644 --- a/src/modules/ranking.ts +++ b/src/modules/ranking.ts @@ -70,9 +70,16 @@ export function topByUpdate( origin: AppOrigin, topN: number = TOP_N, ): App[] { + // 按 update 字段倒序;后端日期格式可能不严格一致(如 2026-08-10 / 2026/08/10 / + // 带时分秒),用时间戳数字比较比 localeCompare 字符串比较更鲁棒。 + // 无效日期 getTime() 为 NaN,统一按 0 处理,避免 NaN 参与比较导致乱序。 + const toTime = (s: string | undefined): number => { + const t = new Date(s || "").getTime(); + return Number.isFinite(t) ? t : 0; + }; return apps .filter((a) => a.origin === origin && a.update) - .sort((a, b) => (b.update || "").localeCompare(a.update || "")) + .sort((a, b) => toTime(b.update) - toTime(a.update)) .slice(0, topN); }