🐛 修复多设备同步脚本排序错乱 - #1690
Open
CodFrm wants to merge 2 commits into
Open
Conversation
Collaborator
|
本次基于原 PR head 追加修正 commit:
验证结果:
远端 GitHub Actions 的 |
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.
Checklist / 检查清单
背景
脚本排序沿用脚本内容的
updatetime参与状态同步。排序本身没有可靠推进该时钟,且状态中的启用与排序共用同一个冲突维度,导致两台设备通过云同步排序后可能采用过期位置并打乱顺序。10 脚本真实浏览器复现中,期望顺序6,1,2,3,4,5,7,8,9,10会收敛为7,8,9,10,6,1,2,3,4,5。本次改动
scriptcat-sync.json的脚本状态增加可选sortUpdatetime,将启用状态与排序状态按各自时钟合并。updatetime。pending_sort_status,Service Worker 重启后继续同步,成功写入对应排序时钟后才清理。Script.sort,不增加 Script 字段、数据库表、排序版本号或插入排序模型。sortUpdatetime时原有整条状态 LWW 行为,兼容旧版scriptcat-sync.json。实现考虑
排序事件和全量同步复用同一云同步任务队列,避免同步写回期间清除更新的排序意图。写回前的二次云端读取分别选择较新的启用状态和排序状态;缺少排序时钟的一侧使用
updatetime作为兼容回退。真实浏览器复现还发现历史
sort=-1会被getAllScripts()本地规范化但不进入同步。该路径现在会等待批量写入,并只为位置发生变化的脚本登记排序时钟。已知限制
建议审查重点
scriptcat-sync.json混用时的兼容回退及启用/排序双轴合并。Script.updatetime不变。关联
Fixes #1682
验证
pnpm exec vitest run src/app/service/service_worker/synchronize.test.ts src/app/service/service_worker/script.test.ts— 2 files / 162 tests passed。pnpm run lint— Prettier、TypeScript、i18n、issue templates、ESLint passed。pnpm exec vitest run— 4201 passed;11 个并发 timeout,未出现本改动相关断言失败。pnpm exec vitest run scripts/git-staged-snapshot.test.mjs src/pages/confirm/App.test.tsx src/pages/options/routes/Agent/OPFS/index.test.tsx src/locales/i18n-usage.test.ts tests/runtime/gm_api.test.ts src/app/service/service_worker/trash_event_partition.test.ts src/app/service/agent/service_worker/task_service.test.ts— 首轮 timeout 的 7 files / 54 tests passed。pnpm run dev— MV3 扩展构建成功;有 Monaco 动态require的既有 warning。updatetime。git diff --check— passed。