P2-9 修复: portal release 性能优化 (跳过 loadAppContext, 2026-07-02)
FINDING-P6: portal release 走 loadAppContext 拉 5 个 list (~3-5s 延迟) - 实际只需菜单 list (topLevelMenus) + category-cache (currentSystemId) - 4 个无用 list: forms/dm/workflows/currentUser - portal release 是发布类高频操作, 体验卡 修复: - 直接调 loadMenu.getMenuList() 替代 loadAppContext 5 个 list - 直接读 ~/.dacli-token/category-cache.json 替代走 system list API - 节省 ~3-5s 延迟, 用户感知明显 - 行为一致: 跟 P0-1 tryFetchMenus/topLevelMenus 派生逻辑一样 注意: ctx 仍可 import (loadAppContext 类型), 但实际不调, 留兼容 审计: dacli/docs/cmd-review/v0.14-rollout-audit-2026-07-02.md §3.1 P6
This commit is contained in:
1 parent
daf0e84e2b
commit
370502e5d8
1 file changed
+36
-5
@@ -58,19 +58,50 @@ export function buildPortalReleaseCommand(): Command {
|
||||
// === step 0.5 BS-109: 自动检测 pcModuleParentId/appModuleParentId ===
|
||||
// v0.15+ 修复 (2026-07-02): 用 ctx.topLevelMenus (id+fullName 对象数组) 替代 ctx.menus:string[]
|
||||
// + ctx.currentSystemId 替代不存在的 currentSystemId 字段 (P0-1 已补)
|
||||
// v0.15+ (P2-9, 2026-07-02): 性能优化 — 替代 loadAppContext() (拉 5 个 list ~3-5s 延迟)
|
||||
// 改用单 API: loadMenu.getMenuList() (拉菜单) + loadSystem.getSystemList() (拉 currentSystemId)
|
||||
// 节省 4 个无用 list 调用 (forms/dm/workflows/currentUser)
|
||||
let pcSystemId = opts.pcSystemId
|
||||
let pcModuleParentId = opts.pcModuleParentId
|
||||
let appSystemId = opts.appSystemId
|
||||
let appModuleParentId = opts.appModuleParentId
|
||||
try {
|
||||
const ctx = await loadAppContext()
|
||||
if (!pcSystemId && ctx.currentSystemId) pcSystemId = ctx.currentSystemId
|
||||
if (!appSystemId && ctx.currentSystemId) appSystemId = ctx.currentSystemId
|
||||
// 先从 ~/.dacli-token/category-cache.json 读 currentSystemId (跟 P0-1 一致)
|
||||
// category-cache 通常都有, 1 次 fs.readFile 即可, 免去调 system list API
|
||||
if (!pcSystemId || !appSystemId) {
|
||||
try {
|
||||
const { homedir } = await import('node:os')
|
||||
const { join, resolve } = await import('node:path')
|
||||
const { existsSync, readFileSync } = await import('node:fs')
|
||||
const dir = process.env.DACLI_TOKEN_DIR ? resolve(process.env.DACLI_TOKEN_DIR) : join(homedir(), '.dacli-token')
|
||||
const cachePath = join(dir, 'category-cache.json')
|
||||
if (existsSync(cachePath)) {
|
||||
const cache = JSON.parse(readFileSync(cachePath, 'utf-8')) as Record<string, { id?: string }>
|
||||
if (cache[c.appCode]?.id) {
|
||||
if (!pcSystemId) pcSystemId = cache[c.appCode].id
|
||||
if (!appSystemId) appSystemId = cache[c.appCode].id
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// 读失败, 后续兜底
|
||||
}
|
||||
}
|
||||
|
||||
// 直接调 menu list (替代 loadAppContext 拉 5 个 list)
|
||||
// topLevelMenus 派生自 menu list 的 parentId=0/-1 过滤 (跟 P0-1 tryFetchMenus 行为一致)
|
||||
const menuWebapi = await import('../../webapi/menu.ts')
|
||||
await menuWebapi.initWebapi(c)
|
||||
const menuResp = (await menuWebapi.loadMenu.getMenuList()) as { data?: { list?: Array<{ id?: string; fullName?: string; parentId?: string | number; enCode?: string; category?: string }> } } | unknown
|
||||
const allMenus = (menuResp as { data?: { list?: unknown[] } })?.data?.list
|
||||
|| (Array.isArray(menuResp) ? menuResp as unknown[] : [])
|
||||
const topLevelMenus = (allMenus as Array<{ id?: string; fullName?: string; parentId?: string | number; enCode?: string; category?: string }>)
|
||||
.filter((m) => m && (m.parentId === '0' || m.parentId === '-1' || m.parentId === 0 || m.parentId === -1))
|
||||
.map((m) => ({ id: String(m.id || ''), fullName: m.fullName, parentId: String(m.parentId ?? ''), enCode: m.enCode, category: m.category }))
|
||||
.filter((m) => m.id)
|
||||
|
||||
// 自动检测顶级菜单 (BS-109, 跟 BS-106 menu create 模式一致)
|
||||
// FINDING-P4 (2026-07-02 audit): PC/App 端菜单树分离, 应分别取
|
||||
// category: 'Web' / 'App' (web 端 ReleaseModal.vue:104/108 行为)
|
||||
const topLevelMenus = ctx.topLevelMenus || []
|
||||
const pcTop = topLevelMenus.find((m) => m.category === 'Web' || m.category === undefined || m.category === '')
|
||||
const appTop = topLevelMenus.find((m) => m.category === 'App')
|
||||
if (topLevelMenus.length > 0) {
|
||||
@@ -94,7 +125,7 @@ export function buildPortalReleaseCommand(): Command {
|
||||
log.warn(` 或显式传 --pcModuleParentId=<menu_id> --pcSystemId=<systemId>`)
|
||||
}
|
||||
} catch (e) {
|
||||
log.warn(`BS-109: AppContext 加载失败 (${(e as Error).message?.slice(0, 100)}), 跳过自动检测`)
|
||||
log.warn(`BS-109: menu/system 加载失败 (${(e as Error).message?.slice(0, 100)}), 跳过自动检测`)
|
||||
}
|
||||
|
||||
// === step 1 构造 pc/app/platformRelease (镜像 web ReleaseModal.vue:80) ===
|
||||
|
||||
Reference in new issue
Block a user