updateFileProgress 更新文件进度(对外安全接口) 如果批次存在,会对 batch.mu 加锁后调用 updateFileProgressNoLock;否则直接持久化到 storage
(batchID, fileID string, fileUpload *FileUpload)
| 385 | // updateFileProgress 更新文件进度(对外安全接口) |
| 386 | // 如果批次存在,会对 batch.mu 加锁后调用 updateFileProgressNoLock;否则直接持久化到 storage |
| 387 | func (m *BatchUploadManager) updateFileProgress(batchID, fileID string, fileUpload *FileUpload) { |
| 388 | // 先快速获取 batch 指针(使用读锁),避免长期持有全局锁 |
| 389 | m.mu.RLock() |
| 390 | batch, exists := m.batches[batchID] |
| 391 | m.mu.RUnlock() |
| 392 | if !exists { |
| 393 | // 保存到存储(尽量保持幂等) |
| 394 | m.progressStorage.UpdateFileProgress(batchID, fileID, fileUpload) |
| 395 | return |
| 396 | } |
| 397 | |
| 398 | // 使用 batch 的 mutex 保护对 batch.Files 的写入 |
| 399 | batch.mu.Lock() |
| 400 | defer batch.mu.Unlock() |
| 401 | m.updateFileProgressNoLock(batch, fileID, fileUpload) |
| 402 | } |
| 403 | |
| 404 | // updateBatchStatus 更新批次状态 |
| 405 | func (m *BatchUploadManager) updateBatchStatus(batch *BatchUpload) { |
no test coverage detected