mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 14:08:06 +08:00
perf: 优化计划任务备份列表打开速度 (#3740)
This commit is contained in:
parent
045dbaef91
commit
10eef260d4
@ -8,7 +8,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
||||||
@ -81,7 +83,6 @@ func (u *BackupService) List() ([]dto.BackupInfo, error) {
|
|||||||
func (u *BackupService) SearchRecordsWithPage(search dto.RecordSearch) (int64, []dto.BackupRecords, error) {
|
func (u *BackupService) SearchRecordsWithPage(search dto.RecordSearch) (int64, []dto.BackupRecords, error) {
|
||||||
total, records, err := backupRepo.PageRecord(
|
total, records, err := backupRepo.PageRecord(
|
||||||
search.Page, search.PageSize,
|
search.Page, search.PageSize,
|
||||||
commonRepo.WithOrderBy("created_at desc"),
|
|
||||||
commonRepo.WithByName(search.Name),
|
commonRepo.WithByName(search.Name),
|
||||||
commonRepo.WithByType(search.Type),
|
commonRepo.WithByType(search.Type),
|
||||||
backupRepo.WithByDetailName(search.DetailName),
|
backupRepo.WithByDetailName(search.DetailName),
|
||||||
@ -91,13 +92,15 @@ func (u *BackupService) SearchRecordsWithPage(search dto.RecordSearch) (int64, [
|
|||||||
}
|
}
|
||||||
|
|
||||||
datas, err := u.loadRecordSize(records)
|
datas, err := u.loadRecordSize(records)
|
||||||
|
sort.Slice(datas, func(i, j int) bool {
|
||||||
|
return datas[i].CreatedAt.After(datas[j].CreatedAt)
|
||||||
|
})
|
||||||
return total, datas, err
|
return total, datas, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *BackupService) SearchRecordsByCronjobWithPage(search dto.RecordSearchByCronjob) (int64, []dto.BackupRecords, error) {
|
func (u *BackupService) SearchRecordsByCronjobWithPage(search dto.RecordSearchByCronjob) (int64, []dto.BackupRecords, error) {
|
||||||
total, records, err := backupRepo.PageRecord(
|
total, records, err := backupRepo.PageRecord(
|
||||||
search.Page, search.PageSize,
|
search.Page, search.PageSize,
|
||||||
commonRepo.WithOrderBy("created_at desc"),
|
|
||||||
backupRepo.WithByCronID(search.CronjobID),
|
backupRepo.WithByCronID(search.CronjobID),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -105,6 +108,9 @@ func (u *BackupService) SearchRecordsByCronjobWithPage(search dto.RecordSearchBy
|
|||||||
}
|
}
|
||||||
|
|
||||||
datas, err := u.loadRecordSize(records)
|
datas, err := u.loadRecordSize(records)
|
||||||
|
sort.Slice(datas, func(i, j int) bool {
|
||||||
|
return datas[i].CreatedAt.After(datas[j].CreatedAt)
|
||||||
|
})
|
||||||
return total, datas, err
|
return total, datas, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -437,6 +443,7 @@ func (u *BackupService) loadAccessToken(backup *model.BackupAccount) error {
|
|||||||
func (u *BackupService) loadRecordSize(records []model.BackupRecord) ([]dto.BackupRecords, error) {
|
func (u *BackupService) loadRecordSize(records []model.BackupRecord) ([]dto.BackupRecords, error) {
|
||||||
var datas []dto.BackupRecords
|
var datas []dto.BackupRecords
|
||||||
clientMap := make(map[string]loadSizeHelper)
|
clientMap := make(map[string]loadSizeHelper)
|
||||||
|
var wg sync.WaitGroup
|
||||||
for i := 0; i < len(records); i++ {
|
for i := 0; i < len(records); i++ {
|
||||||
var item dto.BackupRecords
|
var item dto.BackupRecords
|
||||||
if err := copier.Copy(&item, &records[i]); err != nil {
|
if err := copier.Copy(&item, &records[i]); err != nil {
|
||||||
@ -464,10 +471,15 @@ func (u *BackupService) loadRecordSize(records []model.BackupRecord) ([]dto.Back
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if clientMap[records[i].Source].isOk {
|
if clientMap[records[i].Source].isOk {
|
||||||
item.Size, _ = clientMap[records[i].Source].client.Size(path.Join(clientMap[records[i].Source].backupPath, itemPath))
|
wg.Add(1)
|
||||||
|
go func(index int) {
|
||||||
|
item.Size, _ = clientMap[records[index].Source].client.Size(path.Join(clientMap[records[index].Source].backupPath, itemPath))
|
||||||
|
datas = append(datas, item)
|
||||||
|
wg.Done()
|
||||||
|
}(i)
|
||||||
}
|
}
|
||||||
datas = append(datas, item)
|
|
||||||
}
|
}
|
||||||
|
wg.Wait()
|
||||||
return datas, nil
|
return datas, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user