fix(snapshot): 进度写 DB 改为每 2 秒一次,避免前端长时间显示 0%

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-02-24 01:40:32 -08:00
parent f14f685ea9
commit 669a8a7248
1 changed files with 5 additions and 2 deletions

View File

@ -112,10 +112,13 @@ export class SnapshotOrchestratorService implements OnModuleInit {
throw new Error(`备份处理器不存在: ${target}`);
}
let lastDbWriteTime = 0;
const result = await handler.execute(outputDir, (percent, msg) => {
this.gateway.emitProgress(taskId, target, percent, msg);
// 进度更新不频繁写库每10%写一次
if (percent % 10 === 0) {
// 每 2 秒写一次 DB保证前端轮询能看到进度变化
const now = Date.now();
if (now - lastDbWriteTime >= 2000) {
lastDbWriteTime = now;
this.repo.updateDetailProgress(taskId, target, percent).catch(() => {});
}
});