Skip to content

fix: 提交扫描哈希时只移除已提交条目,避免哈希白算 - #240

Open
CorrectRoadH wants to merge 1 commit into
haierkeys:masterfrom
CorrectRoadH:upstream/fix/scanned-hash-commit
Open

fix: 提交扫描哈希时只移除已提交条目,避免哈希白算#240
CorrectRoadH wants to merge 1 commit into
haierkeys:masterfrom
CorrectRoadH:upstream/fix/scanned-hash-commit

Conversation

@CorrectRoadH

Copy link
Copy Markdown
Contributor

问题

scannedNoteHashes / scannedFileHashes / scannedConfigHashes 是挂在 syncState 上的全局表,不是每轮同步的局部变量。于是两轮同步交叠时会互相清空:

  • 新一轮 handleSync 开头 resetSyncTasks()resetSession() 整表 clear(),清掉上一轮刚算出的哈希;
  • 旧一轮收尾时 bulkSetFromScanned(...) 之后又整表 clear(),把新一轮刚算出、还没落盘的哈希一起抹掉。

结果:哈希算了但存不进 fileHashManager,下次同步 getValidHash 依然 miss,同一批文件反复重算。手机切后台回前台每次都像在做一次完整哈希计算,根因就在这里。

修复

  • 新增 commitScannedHashes():提交后只按键删除本次已提交的条目;
  • resetSession() 不再清空这三张表(条目自带 mtime/size 校验,留到下一轮提交依然有效)。

bulkSetFromScanned 只写本地缓存表、不碰同步基准表,所以保留未提交条目不会影响 baseHash 判定。

已跑 tsc -noEmit -skipLibCheck 通过。

🤖 Generated with Claude Code

https://claude.ai/code/session_01T2QYrNjmd1hNqgzWyR4jFZ

scannedNoteHashes/scannedFileHashes/scannedConfigHashes 挂在 syncState 上是全局表。
重连触发新一轮同步时 resetSession() 会整表 clear,旧一轮收尾时的 bulkSetFromScanned
之后也整表 clear,两边互相清掉对方刚算出、还没落盘的哈希。结果是哈希算了存不进缓存,
下次同步继续 miss 重算 —— 手机切后台回来每次都像在做一次完整哈希计算。

改为:提交后按键删除已提交条目;resetSession 不再清空这三张表。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T2QYrNjmd1hNqgzWyR4jFZ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant