MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / LoadRecordSize

Method LoadRecordSize

agent/app/service/backup_record.go:212–288  ·  view source on GitHub ↗
(req dto.SearchForSize)

Source from the content-addressed store, hash-verified

210}
211
212func (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)

Callers

nothing calls this directly

Calls 9

NewBackupClientMapFunction · 0.85
PageMethod · 0.65
WithByLikeNameMethod · 0.65
PageRecordMethod · 0.65
WithByCronIDMethod · 0.65
WithByTypeMethod · 0.65
WithByDetailNameMethod · 0.65
SizeMethod · 0.65
WaitMethod · 0.45

Tested by

no test coverage detected