fix: reduce sqlite write pressure during scans

This commit is contained in:
ShukeBta
2026-06-11 21:45:53 +08:00
parent 0e28d07122
commit 7d0afd0fcb
6 changed files with 233 additions and 41 deletions
+8 -2
View File
@@ -946,10 +946,16 @@ func (d *DownloadService) syncDownloadTaskProgress(ctx context.Context, torrent
if strings.TrimSpace(status) == "" {
status = matched.Status
}
updates := map[string]any{"progress": torrent.Progress}
if status != "" {
updates := map[string]any{}
if math.Abs(float64(matched.Progress-torrent.Progress)) > 0.0001 {
updates["progress"] = torrent.Progress
}
if status != "" && status != matched.Status {
updates["status"] = status
}
if len(updates) == 0 {
return
}
_ = d.repo.DB.WithContext(ctx).Model(&model.DownloadTask{}).Where("id = ?", matched.ID).Updates(updates).Error
}