perf(代码审查落地): 后端 A1-A8 与前端 C1-C8 加固,retention 清理补索引(V141)

A 组(backend-java):
- A1 载荷引用计数不再无条件回落全表 COUNT
- A2 结果行读取由 LIMIT 1 改整页
- A3 ziniao 索引缓存过期判断下推 SQL
- A4 循环子任务认领改 CAS,失败一律抛
- A5 建单事务里不碰外部 IO
- A6 连接池补网络层超时(connectTimeout/socketTimeout,env 可覆盖)
- A7 日志留现场 + 异步落盘
- A8 其余:货源图片预取、结果工作簿装配等
- V141:三条 retention DELETE 的可用索引,其中 biz_price_track_loop_run
  用 STORED 生成列承载 COALESCE 时间线(该表实测 881 行/17MB,COPY 秒级)

C 组(frontend-vue):URL 取值走 safe-url、行号取值走 row-id、
交付视频任务状态抽成 delivery-video-task-state.ts,各补用例。
This commit is contained in:
2026-10-03 12:24:16 +08:00
parent fd9aa2caa5
commit 37592a3b62
32 changed files with 1065 additions and 292 deletions
@@ -4,6 +4,8 @@
* - 服务端(/api/user-secrets)是唯一权威:按登录用户绑定,客户端只缓存元数据与最近输入的值;
* - `getStoredApiSecret` / `getStoredApiSecretSnapshot` 保持同步读语义(提交任务瞬间立即取用),
* 读取顺序:内存 → 本地镜像 → 旧版 v1 记录(`brand:api-secret:{uid}:{moduleKey}`);
* - 本地镜像(localStorage)在浏览器形态只存脱敏值与状态位,明文只活在本页内存;
* 桌面形态(有 window.pywebview.api 原生存储)维持原有整条镜像,不动既有流程;
* - 保存/清空/检测走异步接口;服务端拉取失败一律软失败(返回 unknown,不阻断使用);
* - 旧版本地密钥在首次加载时自动迁移到服务端(只填空缺、不覆盖)。
*/
@@ -28,7 +30,10 @@ export type { UserApiSecretCheckResult }
export type ApiSecretLoadState = 'complete' | 'incomplete' | 'unknown'
export interface ApiSecretSnapshot {
/** 本地明文缓存(来自用户输入或旧记录迁移);服务端不回传明文,换机后可能为空。 */
/**
* 本地明文(来自用户输入或旧记录迁移),只存内存 Map;
* 浏览器形态的磁盘镜像不含此字段,服务端不回传明文,换机/刷新后可能为空。
*/
value: string
/** 服务端脱敏值(权威展示,如 sk-a****1234)。 */
masked: string
@@ -93,6 +98,19 @@ function buildLegacyKey(moduleKey: string) {
return `${LEGACY_PREFIX}:${currentUid()}:${moduleKey}`
}
/**
* 形态判定:桌面客户端(pywebview)会注入 window.pywebview.api 并提供原生 app.json 存储,
* 其本地明文缓存是既有任务链路依赖(重启后仍能取用);纯浏览器形态没有原生存储,
* localStorage 是同页脚本可直接读到的明文落点,必须收紧。
*
* 这里刻意用内联的 window 断言而不是 import hasPywebview():静态引入 bridges/pywebview
* 会把 web-fallback → http 拉进 node 测试环境(本模块被单测直接 import)。
*/
function isNativeDesktopStorage(): boolean {
if (typeof window === 'undefined') return false
return Boolean((window as unknown as { pywebview?: { api?: unknown } }).pywebview?.api)
}
function emptyEntry(): ApiSecretCacheEntry {
return {
schema: 2,
@@ -128,7 +146,7 @@ function readMirror(moduleKey: string): ApiSecretCacheEntry | null {
if (!raw) return null
const parsed = JSON.parse(raw) as Partial<ApiSecretCacheEntry>
if (parsed.schema !== 2) return null
return {
const entry: ApiSecretCacheEntry = {
schema: 2,
value: typeof parsed.value === 'string' ? parsed.value : '',
masked: typeof parsed.masked === 'string' ? parsed.masked : '',
@@ -141,15 +159,23 @@ function readMirror(moduleKey: string): ApiSecretCacheEntry | null {
checkedAt: typeof parsed.checkedAt === 'number' ? parsed.checkedAt : null,
updatedAt: typeof parsed.updatedAt === 'number' ? parsed.updatedAt : null,
}
// 浏览器形态:历史版本可能已把明文写进磁盘,读到就顺手抹掉(明文只留内存)
if (entry.value && !isNativeDesktopStorage()) {
entry.value = ''
writeMirror(moduleKey, entry)
}
return entry
} catch {
return null
}
}
/** 磁盘镜像写入:浏览器形态只写脱敏值与状态位,明文不落地;桌面形态维持既有整条镜像。 */
function writeMirror(moduleKey: string, entry: ApiSecretCacheEntry) {
if (typeof window === 'undefined') return
const persisted: ApiSecretCacheEntry = isNativeDesktopStorage() ? entry : { ...entry, value: '' }
try {
window.localStorage.setItem(buildMirrorKey(moduleKey), JSON.stringify(entry))
window.localStorage.setItem(buildMirrorKey(moduleKey), JSON.stringify(persisted))
} catch {
/* 本地镜像写入失败不影响主流程 */
}