fix(backup): prevent polling from restarting after navigation

This commit is contained in:
chihao.ou committed 2026-09-30 02:50:29 +08:00
1 parent a60a29549f
commit 00a922c429
2 files changed
+25

No files matched your search

+4
View File
@@ -537,6 +537,7 @@ const downloadPartsModalOpen = ref(false)
const pollingTimer = ref<ReturnType<typeof setInterval> | null>(null)
const restoringPollingTimer = ref<ReturnType<typeof setInterval> | null>(null)
const MAX_POLL_COUNT = 900
let disposed = false
function updateRecordInList(updated: BackupRecord) {
const idx = backups.value.findIndex(r => r.id === updated.id)
@@ -546,6 +547,7 @@ function updateRecordInList(updated: BackupRecord) {
}
function startPolling(backupId: string) {
if (disposed) return
stopPolling()
let count = 0
pollingTimer.value = setInterval(async () => {
@@ -582,6 +584,7 @@ function stopPolling() {
}
function startRestorePolling(backupId: string) {
if (disposed) return
stopRestorePolling()
let count = 0
restoringPollingTimer.value = setInterval(async () => {
@@ -930,6 +933,7 @@ onMounted(async () => {
})
onBeforeUnmount(() => {
disposed = true
stopPolling()
stopRestorePolling()
document.removeEventListener('visibilitychange', handleVisibilityChange)
@@ -108,6 +108,27 @@ describe('admin BackupView', () => {
document.body.innerHTML = ''
})
it.each(['backup', 'restore'])('does not resume %s polling after navigation during initial loading', async (operation) => {
vi.useFakeTimers()
let finish!: (value: object) => void
listBackups.mockImplementationOnce(() => new Promise(resolve => { finish = resolve }))
const wrapper = mountBackupView()
try {
await flushPromises()
wrapper.unmount()
finish({ items: [{ ...baseRecord('pending'),
status: operation === 'backup' ? 'running' : 'completed',
restore_status: operation === 'restore' ? 'running' : undefined,
}] })
await flushPromises()
expect(vi.getTimerCount()).toBe(0)
} finally {
wrapper.unmount()
vi.clearAllTimers()
vi.useRealTimers()
}
})
it('显示分卷数并在下载时列出每个分卷链接', async () => {
listBackups.mockResolvedValue({
items: [baseRecord('split', [{ index: 1 }, { index: 2 }, { index: 3 }])],