fix: 提交扫描哈希时只移除已提交条目,避免哈希白算 - #240
Open
CorrectRoadH wants to merge 1 commit into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
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