mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-09-20 21:50:11 +08:00
fix: 排行榜日期比较鲁棒性 + 下载计数请求取消
- ranking.ts: topByUpdate 改用时戳数字比较,兼容后端不一致的日期格式 (如 2026-08-10 / 2026/08/10 / 带时分秒),无效日期兜底为 0 避免 NaN 乱序 - App.vue: fetchDownloadCount 的 fetch 加 rootAbortController.signal, 组件卸载时可取消未完成请求,避免内存泄漏 (注: 这两个真实缺陷由 PR 审查在错误 diff 下点名,本提交独立于 Erotica PR)
This commit is contained in:
@@ -1311,6 +1311,7 @@ const fetchDownloadCount = async (app: App): Promise<number> => {
|
||||
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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user