🐛 云同步不再随 SW 冷启动触发,闹钟周期改为 30 分钟 - #1678
Merged
Merged
Conversation
MV3 的 Service Worker 空闲即被回收,每次冷启动都会重跑 init 并用当前配置回调一次 `cloud_sync` 的 watch;`cloudSyncConfigChange` 在无 previous 时会直接跑一次全量 `syncOnce`。而 `agentTaskScheduler` 闹钟每分钟唤醒一次 SW,于是实际同步频率退化成 「每分钟一轮」,60 分钟的 `cloudSync` 闹钟形同虚设。 实测(真实 S3,经计数代理):浏览器完全空闲 8 分钟 = 7 轮全量同步 = 34 个 S3 请求。 改为冷启动只 `ensureCloudSyncAlarm()`,同步交给闹钟;启用瞬间、「立即同步」按钮、 脚本安装/删除的事件推送均不变。闹钟成为唯一的周期性入口后,处理器改走 `cloudSyncOnce()`(自带启用校验与失败状态写入)并补 `.catch`,否则连接失败会在 每轮闹钟留下一个未捕获 rejection。 同一窗口修复后为 0 轮 / 0 请求。 Close #1670
Graph 个人版对 special/ 寻址的 POST children 一律返回 400 invalidRequest,
建目录必须改用 /me/drive/items/{approotId} 寻址;id 在实例内缓存一次。
读取与上传路径不受影响。
Collaborator
|
已基于原 PR head 修正 commits:
验证结果:
|
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 / 检查清单
Description / 描述
Close #1670
背景
用户把云同步接到 S3 桶后发现「同步频率设成每天,结果每分钟调用五次接口」。
MV3 的 Service Worker 空闲即被回收,每次冷启动都会重跑
init()并用当前配置回调一次cloud_sync的watch(SystemConfig.watch注册时会立即执行一次回调)。cloudSyncConfigChange在无previous时会直接跑一次全量syncOnce——而
agentTaskScheduler闹钟每分钟唤醒一次 SW,于是实际同步频率退化成「每分钟一轮」,60 分钟的
cloudSync闹钟形同虚设。v1.4.0 与当前 main 都有这个问题(v1.4.0 连配置等价判重都没有,另外还多一个
extension_initialized触发点)。顺带说明:云同步并没有频率设置项,设置页上紧挨着同步卡片的「每天」是脚本更新检查周期,
报告人把它当成同步周期了。
本次改动
ensureCloudSyncAlarm(),不再同步;周期同步交给闹钟。cloudSync闹钟周期 60 → 30 分钟。getCloudSync → buildFileSystem → syncOnce改走
synchronize.cloudSyncOnce()(自带启用校验与失败状态写入)并补.catch——原来连接失败会在每轮闹钟留下一个未捕获 rejection。
不变:勾选启用的瞬间仍立即同步一次、设置页「立即同步」按钮、脚本安装/删除的事件推送。
第二个提交是顺带修的 OneDrive 建目录问题(Graph 个人版对
special/寻址的 POST children返回 400 invalidRequest,改用
/me/drive/items/{approotId}寻址)。验证
单元测试按 TDD 先写 RED 再实现:
真机复现与验收(真实 MinIO,扩展的 S3 端点指向一个逐请求记账的透传代理;
脱离调试器运行,因为 CDP 附着会阻止 MV3 SW 被回收、这个 bug 就不出现):
修复前的轮次起点:
02:09:57 / 02:10:57 / 02:11:58 / 02:12:57 / 02:14:00 / 02:15:59 / 02:16:57,每轮
HEAD+LIST+GET+PUT+LIST,与 issue 里贴的 5 条日志一致。修复后仍验证了三条该保留的路径:
02:37:52一轮);02:39:17排程 →02:39:17.264起一轮(只替换触发时刻,处理器与同步链路是真实的);chrome.alarms.getAll()实测cloudSync period=30min。.catch单独验证:停掉代理制造真实连接失败,日志出现cloud sync alarm failed,整个会话
[exception]计数为 0。另做了一次不经过代理的独立回读(扩展页
chrome.storage.local):空闲窗口后lastSyncAt仍停在02:39:18、enable=true;而这次回读本身又是一次冷启动,lastSyncAt未推进。已知限制
同步周期仍是硬编码,可配置化是单独的 feature。
agentTaskScheduler仍每分钟唤醒一次 SW,无条件创建、不受 Agent 开关约束。修完后它不再产生 S3 请求,但每分钟冷启一次 SW 的开销仍在,属另一个 issue,本 PR 未动。