perf: 大文档性能优化——1.getMarkdown 防抖 300ms: 2000-5000 行文档每次按键序列化全量 markdown 开销大, 改为 debounce 300ms; 2.dsh-flush-body 事件: Ctrl+S/关窗/切文档前同步编辑器内容到 store, 确保保存不丢内容; 3.openDoc 不 await saveNow: 旧文档保存与新文档读取并行, 加快切换速度; 4.自动保存间隔 1s→3s: 大文档每秒写盘 I/O 压力大; 5.修复 save-mechanism E2E 测试时序适配新防抖

This commit is contained in:
hunter-dev
2026-08-27 15:48:19 +08:00
parent 3fe35ef873
commit ebd955ce4b
4 changed files with 32 additions and 8 deletions
+2 -2
View File
@@ -49,7 +49,7 @@ export function App() {
}).catch(() => {}); } }, [activeId]);
// FR-S4:关窗前冲刷未保存内容
useEffect(() => {
const onBeforeUnload = () => { try { useStore.getState().saveNow(); } catch {} };
const onBeforeUnload = () => { try { window.dispatchEvent(new CustomEvent('dsh-flush-body')); useStore.getState().saveNow(); } catch {} };
window.addEventListener('beforeunload', onBeforeUnload);
return () => window.removeEventListener('beforeunload', onBeforeUnload);
}, []);
@@ -62,7 +62,7 @@ export function App() {
await useStore.getState().loadTree();
await useStore.getState().openDoc(path);
},
onSave: () => useStore.getState().saveNow(),
onSave: () => { window.dispatchEvent(new CustomEvent('dsh-flush-body')); useStore.getState().saveNow(); },
onFocusSearch: () => { const el = document.querySelector('input[placeholder*="搜索"]') as HTMLInputElement; el?.focus(); },
onToggleOutline: () => layout.toggleOutline(),
onCheat: () => setShowCheat(true),