fix(storage): 旧 data.json 副本与文件一致时不再标脏(避免每次启动重写全部画布)
Verify (Gitea) / gate (build · unit · facts) (push) Canceled after 1m4s
Verify (Gitea) / gate (build · unit · facts) (push) Canceled after 1m4s
This commit is contained in:
1 parent
16f33128da
commit
0cdeadf0cd
2 files changed
+14
-3
No files matched your search
+13
-2
@@ -741,6 +741,8 @@
|
||||
}
|
||||
} catch (e) { /* ignore */ }
|
||||
}
|
||||
// 2026-12-04:id → 文件内容(判断 data.json 的旧副本是否真的需要迁移)
|
||||
const fileTexts = {}
|
||||
// 画布:一张画布一个文件(canvases/<id>.json,内容就是该键的原始 JSON)
|
||||
try {
|
||||
const cdir = await join(dir, CANVAS_DIR)
|
||||
@@ -752,7 +754,9 @@
|
||||
for (const e of wsFiles) {
|
||||
try {
|
||||
const text = await fs().readTextFile(await join(cdir, e.name))
|
||||
mem['iwb_ws_' + e.name.replace(/\.json$/, '')] = text
|
||||
const wid = e.name.replace(/\.json$/, '')
|
||||
mem['iwb_ws_' + wid] = text
|
||||
fileTexts[wid] = text
|
||||
} catch (e) { /* 单个画布读失败不影响其它 */ }
|
||||
wsRead++
|
||||
bpReport('canvases', wsRead, wsFiles.length)
|
||||
@@ -775,7 +779,14 @@
|
||||
}
|
||||
} catch (e) { /* 目录还没有 */ }
|
||||
// 旧格式:画布还压在 data.json 里 ⇒ 标脏,下一次 flush 拆成单文件
|
||||
if (fromDataJson) for (const k of Object.keys(parsed.keys || {})) if (isWsKey(k)) dirtyWs.add(k)
|
||||
// 2026-12-04:只有「文件缺失」或「data.json 里的旧副本与文件内容不同」才标脏;
|
||||
// 原来只要 data.json 残留 ws 键就全部标脏 ⇒ 每次启动重写所有画布(用户实测 mtime 全变)。
|
||||
if (fromDataJson) for (const k of Object.keys(parsed.keys || {})) {
|
||||
if (!isWsKey(k)) continue
|
||||
const wid = k.slice(WS_PREFIX.length)
|
||||
const oldText = fileTexts[wid]
|
||||
if (oldText === undefined || String(oldText) !== String(parsed.keys[k])) dirtyWs.add(k)
|
||||
}
|
||||
// 2026-12-04:记下当前内容签名 —— 启动后第一次 flush 若没实际变化,就不重写 data.json
|
||||
try {
|
||||
const keys0 = {}
|
||||
|
||||
Reference in new issue
Block a user