perf(core): Wave 0 性能根因 — 连接复用/视频轮询脏检查/图懒加载/隐藏tab停轮询

- settings/base.py: MySQL 加 CONN_MAX_AGE=300 + 健康检查 + connect_timeout=5
  (development/production 共用,production 经 from .base import * 继承);development 去重
- App.tsx pollVideosQuiet: 收尾 setProjectDetail 改 JSON 脏检查,在途段未变化时
  跳过 setState,整棵管线不再每 5 秒空重渲染(纯前端,不碰生成业务)
- ai-tools.tsx: 任务历史网格+列表两处 img 补 loading=lazy/decoding=async
- pipeline.tsx: 审核(8s)+在途资产(4s)纯读轮询加 document.hidden 守卫
  (视频5s轮询驱动生成,保守不加;详见进度文档)

验证: tsc 0 · django check 0 · 14 路由 headless boot 0 报错 · 登录 726ms 无假延迟无邮箱

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
seaislee1209
2026-06-19 03:36:07 +08:00
co-authored by Claude Opus 4.8
parent afa8e07154
commit 8a0ae6a19d
7 changed files with 126 additions and 11 deletions
+4 -1
View File
@@ -330,7 +330,10 @@ export function App() {
await Promise.all(active.map((segment) => api.pollVideo(activeProjectId, segment.id).catch(() => undefined)));
const next = await api.project(activeProjectId).catch(() => null);
// 晚到的旧项目轮询结果不要冲掉已切换的当前项目详情
if (next && next.id === activeProjectIdRef.current) setProjectDetail(next);
if (next && next.id === activeProjectIdRef.current) {
// 视频生成动辄数分钟,多数 5s 轮次状态没变 —— 内容一致时跳过 setState,避免整棵管线每 5 秒空重渲染。
setProjectDetail((prev) => (prev && JSON.stringify(prev) === JSON.stringify(next) ? prev : next));
}
}, [activeProjectId]);
// 静默刷新导出任务状态(进入拼接页 / 导出后回填成片),不弹 toast。
+2 -2
View File
@@ -311,7 +311,7 @@ export function AssetFactoryPage({ navigate }: { navigate: (page: Page) => void
const img = taskImage[task.id];
return (
<article className="task-card history-card" key={task.id}>
<div className={`placeholder${img ? " has-img" : ""}`}>{img ? <img src={img} alt={typeLabel} /> : <span className="ph-frame">{task.id.slice(0, 4)}</span>}</div>
<div className={`placeholder${img ? " has-img" : ""}`}>{img ? <img src={img} alt={typeLabel} loading="lazy" decoding="async" /> : <span className="ph-frame">{task.id.slice(0, 4)}</span>}</div>
<div className="history-body">
<div className="history-name">{typeLabel}</div>
<div className="history-type">// {task.task_type}</div>
@@ -346,7 +346,7 @@ export function AssetFactoryPage({ navigate }: { navigate: (page: Page) => void
<td>
<div className="task-name-cell">
<div className={`placeholder task-thumb${img ? " has-img" : ""}`}>
{img ? <img src={img} alt={typeLabel} /> : <span className="ph-frame">{task.id.slice(0, 4)}</span>}
{img ? <img src={img} alt={typeLabel} loading="lazy" decoding="async" /> : <span className="ph-frame">{task.id.slice(0, 4)}</span>}
</div>
<div>
<div className="task-name">{typeLabel}</div>
+2
View File
@@ -802,6 +802,7 @@ export function PipelinePage(props: {
let sawProcessing = false;
let timer = 0;
const tick = async () => {
if (document.hidden) return; // 标签页切走时不空跑审核轮询(纯读,回前台自然恢复)
const r = await api.pollReviews(project.id).catch(() => null);
if (!alive) return;
const map = (r?.reviews || {}) as Record<string, string>;
@@ -2078,6 +2079,7 @@ export function PipelinePage(props: {
let stopped = false;
let timer = 0;
const tick = async () => {
if (document.hidden) { if (!stopped) timer = window.setTimeout(tick, 4000); return; } // 后台不空跑(纯读),保留心跳回前台即恢复
try {
const res = await api.pendingAssets(project.id);
if (stopped) return;