mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-08-06 11:53:56 +08:00
perf(App.vue): 修复首页列表N+1请求问题,优化加载性能
直接使用接口返回的列表数据构建应用对象,不再为每个应用单独请求app.json,应用详情将在用户点击时按需获取
This commit is contained in:
+33
-32
@@ -1201,42 +1201,43 @@ const loadHomeListApps = async (entryId: string) => {
|
|||||||
const path = `/${finalArch}${jsonUrl}`;
|
const path = `/${finalArch}${jsonUrl}`;
|
||||||
const rawApps =
|
const rawApps =
|
||||||
(await fetchWithRetry<Record<string, string>[]>(path)) || [];
|
(await fetchWithRetry<Record<string, string>[]>(path)) || [];
|
||||||
const apps = await Promise.all(
|
// 直接使用列表数据构建 App 对象,避免为每个应用单独请求 app.json(N+1 问题)
|
||||||
rawApps.map(async (a) => {
|
// 应用详情会在用户点击时通过 fetchAppFromStore 按需获取
|
||||||
const category = a.Category || a.category || "unknown";
|
const apps = rawApps.map((a) => {
|
||||||
const pkgname = a.Pkgname || a.pkgname || "";
|
const category = a.Category || a.category || "unknown";
|
||||||
|
|
||||||
// 复用首页逻辑:从仓库获取完整应用信息
|
let img_urls: string[] = [];
|
||||||
|
const rawImgUrls = a.img_urls;
|
||||||
|
if (typeof rawImgUrls === "string") {
|
||||||
try {
|
try {
|
||||||
const realAppUrl = `/${finalArch}/${category}/${pkgname}/app.json`;
|
img_urls = JSON.parse(rawImgUrls);
|
||||||
const realApp = await fetchWithRetry<AppJson>(realAppUrl);
|
} catch {
|
||||||
return normalizeAppJson(realApp, category, mode);
|
img_urls = [];
|
||||||
} catch (e) {
|
|
||||||
console.warn(`Failed to fetch app.json for ${pkgname}`, e);
|
|
||||||
}
|
}
|
||||||
|
} else if (Array.isArray(rawImgUrls)) {
|
||||||
|
img_urls = rawImgUrls;
|
||||||
|
}
|
||||||
|
|
||||||
// 回退:使用列表中的基本信息构建 App 对象
|
return {
|
||||||
return {
|
name: a.Name || a.name || a.Pkgname || a.pkgname || "",
|
||||||
name: a.Name || a.name || pkgname || "",
|
pkgname: a.Pkgname || a.pkgname || "",
|
||||||
pkgname,
|
version: a.Version || "",
|
||||||
version: a.Version || "",
|
filename: a.Filename || a.filename || "",
|
||||||
filename: a.Filename || a.filename || "",
|
torrent_address: a.Torrent_address || "",
|
||||||
category,
|
author: a.Author || "",
|
||||||
more: a.More || a.more || "",
|
contributor: a.Contributor || "",
|
||||||
torrent_address: "",
|
website: a.Website || "",
|
||||||
author: "",
|
update: a.Update || "",
|
||||||
contributor: "",
|
size: a.Size || "",
|
||||||
website: "",
|
more: a.More || a.more || "",
|
||||||
update: "",
|
tags: a.Tags || "",
|
||||||
size: "",
|
img_urls,
|
||||||
tags: "",
|
icons: a.icons || "",
|
||||||
img_urls: [],
|
category,
|
||||||
icons: "",
|
origin: mode,
|
||||||
origin: mode,
|
currentStatus: "not-installed" as const,
|
||||||
currentStatus: "not-installed" as const,
|
} as App;
|
||||||
} as App;
|
});
|
||||||
}),
|
|
||||||
);
|
|
||||||
loadedApps.push(...apps);
|
loadedApps.push(...apps);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.warn(`加载首页列表 ${entryId} (${mode}) 失败: ${e}`);
|
logger.warn(`加载首页列表 ${entryId} (${mode}) 失败: ${e}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user