Skip to content

fix: auto-refresh remote backup directory when cache is stale [fix #310]#312

Merged
shuaiplus merged 1 commit into
shuaiplus:mainfrom
rootphantomer:fix/auto-refresh-remote-browser
Jul 16, 2026
Merged

fix: auto-refresh remote backup directory when cache is stale [fix #310]#312
shuaiplus merged 1 commit into
shuaiplus:mainfrom
rootphantomer:fix/auto-refresh-remote-browser

Conversation

@rootphantomer

Copy link
Copy Markdown
Contributor

Summary

远端备份目录浏览器 (RemoteBackupBrowser) 会将远端存储的响应缓存到 localStorage 中以避免重复网络请求。此前,缓存只在用户手动点击"刷新"按钮或备份/删除操作后才会更新。如果用户在定时备份执行后进入页面,看到的仍然是旧数据。

此变更在每个缓存键旁边记录上次刷新时间 (refreshedAt)。一个 useEffect 在选中目标变化时(包括首次挂载)触发,将当前时间与记录的时间戳对比,如果超过 5 分钟则强制重新拉取数据。

Change Type

  • Bug fix
  • Feature
  • Compatibility update
  • Documentation
  • Refactor

Cross-File Checklist

  • I read CONTRIBUTING.md.
  • Schema changes, if any, updated both runtime schema and migrations/0001_init.sql.
  • Persistent data changes, if any, updated backup export/import or documented why backup is not needed.
  • User-facing text changes, if any, updated all locale files.
  • Bitwarden client compatibility was considered for sync/API shape changes.
  • No secrets, tokens, private deployment values, or real vault data are included.

Checks

  • npx tsc -p tsconfig.json --noEmit
  • npx tsc -p webapp/tsconfig.json --noEmit
  • npm run i18n:validate
  • npm run build

Notes

远端备份目录刷新场景清单

触发刷新的场景

# 触发场景 触发机制 force 代码位置
1 进入页面,缓存过期 (>5min) useEffectsavedSelectedDestination?.id 变化,检查 refreshedAt 过期 true BackupCenterPage.tsx:317-328
2 进入页面,首次加载 (无缓存) lastRefreshed 为 0 → 过期 true BackupCenterPage.tsx:317-328
3 切换备份目标,新目标缓存过期 useEffect 检测 savedSelectedDestination?.id 变化 true BackupCenterPage.tsx:317-328
4 切换备份目标,新目标无缓存 lastRefreshed 为 0 true BackupCenterPage.tsx:317-328
5 手动点击刷新按钮 onRefreshRemoteBrowser 回调 true BackupCenterPage.tsx:1006-1010
6 运行手动备份后 executeRunRemoteBackup 成功后 true BackupCenterPage.tsx:714
7 删除远端备份文件后 executeDeleteRemote 成功后 true BackupCenterPage.tsx:762
8 保存目标设置后 清除该目标的全部缓存 + refreshedAt,下次触发时重新拉取 清除后自然触发 BackupCenterPage.tsx:687-692
9 删除备份目标后 清除该目标全部缓存 + refreshedAt 清除后自然触发 BackupCenterPage.tsx:555-565

不触发刷新的场景

# 场景 原因
1 进入页面,缓存未过期 (5min内) Date.now() - lastRefreshed <= TTL,跳过
2 在同一个目标下导航目录 (进入子目录/返回上级) savedSelectedDestination?.id 不变,useEffect 不触发
3 浏览器标签页切换 (切换到其他标签页再切回来) 没有 visibilitychange / focus 事件监听
4 其他用户操作了备份 (另一个浏览器/设备) 没有 WebSocket / 轮询机制
5 定时备份任务成功执行后 定时备份是服务端执行的,不通知前端刷新

When entering the cloud backup page, the remote backup directory list only showed cached data and required a manual click of the refresh button to see new backup files. This change adds a TTL-based auto-refresh that fetches fresh data when the cache is older than 5 minutes.

Changes:
- Added refreshedAt tracking per cache key in persisted state
- Added REMOTE_BROWSER_REFRESH_TTL_MS (5 min) constant
- Added useEffect that triggers auto-refresh when destination is selected and cached data is stale
- Stamped refresh timestamps after successful API responses
- Cleaned up timestamps on destination delete and settings save
@rootphantomer rootphantomer changed the title fix: auto-refresh remote backup directory when cache is stale[fix https://github.com/shuaiplus/nodewarden/issues/310] fix: auto-refresh remote backup directory when cache is stale [fix #310] Jul 13, 2026
@shuaiplus
shuaiplus merged commit 72d8ec9 into shuaiplus:main Jul 16, 2026
1 check passed
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.

2 participants