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:
@@ -66,8 +66,9 @@ export const useStore = create<EditorState>((set, get) => ({
|
||||
},
|
||||
|
||||
openDoc: async (path: string) => {
|
||||
// 切换前冲刷当前文档
|
||||
await get().saveNow();
|
||||
// 切换前冲刷当前文档——先同步编辑器内容到 store 再保存
|
||||
window.dispatchEvent(new CustomEvent('dsh-flush-body'));
|
||||
void get().saveNow();
|
||||
const doc: ReadDocResult = await invoke(IPC.docRead, { path });
|
||||
set({ currentPath: path, body: doc.body, meta: doc.meta, title: doc.meta.title ?? path.split('/').pop()!.replace(/\.md$/, ''), saveState: 'saved', docMtime: doc.mtime });
|
||||
// 同步到标签页(如已存在则激活,否则新建)
|
||||
@@ -103,7 +104,7 @@ export const useStore = create<EditorState>((set, get) => ({
|
||||
set({ body, saveState: 'saving' });
|
||||
// FR-S1:防抖自动保存——间隔读 settings.autoSaveInterval(秒→毫秒)
|
||||
if (saveTimer) clearTimeout(saveTimer);
|
||||
const interval = (() => { try { const s = JSON.parse(localStorage.getItem('dsh-settings') ?? '{}'); return (s.autoSaveInterval ?? 1) * 1000; } catch { return 1000; } })();
|
||||
const interval = (() => { try { const s = JSON.parse(localStorage.getItem('dsh-settings') ?? '{}'); return (s.autoSaveInterval ?? 3) * 1000; } catch { return 3000; } })();
|
||||
saveTimer = setTimeout(() => { get().saveNow(); }, interval);
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user