perf(webui): trim debug-view rendering cost (json-tree, activity, tester)

- json-tree:折叠节点不再枚举子项(改用 count),整棵树的 JSON.stringify 从每次渲染
  改为点击复制时才算。
- live-activity:搜索命中串在入队时预生成,过滤不再对每行 JSON.stringify(300 行 ×
  每次击键)。
- action-tester:流式帧封顶 2000,长/失控流不再无限增长数组与 DOM。

均行为保持(或纯改善),对抗性 Agent 逐条核验无回归。
This commit is contained in:
DrSmoothl committed 2026-07-02 15:02:13 +08:00
1 parent 99547e847e
commit c85c510c0b
3 files changed
+27 -14

No files matched your search

@@ -25,6 +25,9 @@ const cardCls = 'rounded-2xl border border-border/60 bg-card/80 shadow-[0_1px_2p
// positives just add one extra click; false negatives skip a confirm — both low
// stakes (the amber banner already warns that any write is real).
const DESTRUCTIVE_RE = /(kick|ban|mute|recall|withdraw|delete|del_|dismiss|disband|leave|quit|remove|revoke)/i;
// Cap retained stream frames so a long-running / runaway stream can't grow the
// array and DOM without bound. Generous enough to keep a full normal stream.
const MAX_STREAM_FRAMES = 2000;
function qqAvatarUrl(uin: string) {
return `/avatar/${encodeURIComponent(uin)}`;
@@ -136,7 +139,7 @@ export function ActionTester({ accounts, docs, presetAction }: { accounts: QQInf
try {
await api.debug.invokeStream(uin, actionName.trim(), params, (frame) => {
last = frame;
setFrames((prev) => [...prev, frame]);
setFrames((prev) => (prev.length >= MAX_STREAM_FRAMES ? [...prev.slice(-(MAX_STREAM_FRAMES - 1)), frame] : [...prev, frame]));
const d = frame.data as { type?: string; progress?: number; transferred?: number; total?: number } | undefined;
if (d && typeof d.progress === 'number') tasks.update(taskId, { progress: d.progress });
else if (d && typeof d.transferred === 'number' && typeof d.total === 'number' && d.total > 0) tasks.update(taskId, { progress: d.transferred / d.total });
@@ -14,7 +14,7 @@ import type { DebugStreamMessage } from '@/types';
const STREAM_CAP = 300;
const cardCls = 'rounded-2xl border border-border/60 bg-card/80 shadow-[0_1px_2px_rgb(0_0_0/0.04),0_8px_24px_-12px_rgb(0_0_0/0.10)] backdrop-blur-sm';
interface StreamRow { id: number; at: number; msg: Extract<DebugStreamMessage, { kind: 'event' | 'action' | 'dropped' }> }
interface StreamRow { id: number; at: number; msg: Extract<DebugStreamMessage, { kind: 'event' | 'action' | 'dropped' }>; search: string }
function IconBtn({ onClick, title, children }: { onClick: () => void; title: string; children: ReactNode }) {
return (
@@ -103,7 +103,9 @@ export function LiveActivity() {
(m) => {
if (m.kind === 'ready' || pausedRef.current) return;
setRows((prev) => {
const next = [{ id: idRef.current++, at: Date.now(), msg: m }, ...prev];
// Precompute the search haystack once at enqueue, so filtering never
// re-stringifies every row on each keystroke.
const next = [{ id: idRef.current++, at: Date.now(), msg: m, search: JSON.stringify(m).toLowerCase() }, ...prev];
return next.length > STREAM_CAP ? next.slice(0, STREAM_CAP) : next;
});
},
@@ -119,7 +121,7 @@ export function LiveActivity() {
if (!q) return true;
if (r.msg.kind === 'dropped') return false;
const { label } = rowLabel(r.msg);
return label.toLowerCase().includes(q) || r.msg.uin.includes(q) || JSON.stringify(r.msg).toLowerCase().includes(q);
return label.toLowerCase().includes(q) || r.msg.uin.includes(q) || r.search.includes(q);
});
}, [rows, kindFilter, query]);