(req dto.SearchForSize)
| 210 | } |
| 211 | |
| 212 | func (u *BackupRecordService) LoadRecordSize(req dto.SearchForSize) ([]dto.RecordFileSize, error) { |
| 213 | var list []backupSizeHelper |
| 214 | switch req.Type { |
| 215 | case "snapshot": |
| 216 | _, records, err := snapshotRepo.Page(req.Page, req.PageSize, repo.WithByLikeName(req.Info), repo.WithOrderRuleBy(req.OrderBy, req.Order)) |
| 217 | if err != nil { |
| 218 | return nil, err |
| 219 | } |
| 220 | for _, item := range records { |
| 221 | list = append(list, backupSizeHelper{ID: item.ID, DownloadID: item.DownloadAccountID, FilePath: fmt.Sprintf("system_snapshot/%s.tar.gz", item.Name)}) |
| 222 | } |
| 223 | case "cronjob": |
| 224 | _, records, err := backupRepo.PageRecord(req.Page, req.PageSize, repo.WithOrderDesc("created_at"), backupRepo.WithByCronID(req.CronjobID)) |
| 225 | if err != nil { |
| 226 | return nil, err |
| 227 | } |
| 228 | for _, item := range records { |
| 229 | list = append(list, backupSizeHelper{ID: item.ID, DownloadID: item.DownloadAccountID, FilePath: path.Join(item.FileDir, item.FileName)}) |
| 230 | } |
| 231 | default: |
| 232 | _, records, err := backupRepo.PageRecord( |
| 233 | req.Page, req.PageSize, |
| 234 | repo.WithOrderDesc("created_at"), |
| 235 | repo.WithByName(req.Name), |
| 236 | repo.WithByType(req.Type), |
| 237 | repo.WithByDetailName(req.DetailName), |
| 238 | ) |
| 239 | if err != nil { |
| 240 | return nil, err |
| 241 | } |
| 242 | for _, item := range records { |
| 243 | if item.Status == constant.StatusWaiting { |
| 244 | continue |
| 245 | } |
| 246 | list = append(list, backupSizeHelper{ID: item.ID, DownloadID: item.DownloadAccountID, FilePath: path.Join(item.FileDir, item.FileName)}) |
| 247 | } |
| 248 | } |
| 249 | recordMap := make(map[uint]struct{}) |
| 250 | var recordIds []string |
| 251 | for _, record := range list { |
| 252 | if _, ok := recordMap[record.DownloadID]; !ok { |
| 253 | recordMap[record.DownloadID] = struct{}{} |
| 254 | recordIds = append(recordIds, fmt.Sprintf("%v", record.DownloadID)) |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | clientMap := NewBackupClientMap(recordIds) |
| 259 | var datas []dto.RecordFileSize |
| 260 | var wg sync.WaitGroup |
| 261 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 262 | defer cancel() |
| 263 | for i := 0; i < len(list); i++ { |
| 264 | datas = append(datas, dto.RecordFileSize{ID: list[i].ID}) |
| 265 | if val, ok := clientMap[fmt.Sprintf("%v", list[i].DownloadID)]; ok { |
| 266 | if !val.isOk { |
| 267 | continue |
| 268 | } |
| 269 | wg.Add(1) |
nothing calls this directly
no test coverage detected