mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2025-11-25 03:15:19 +08:00
perf(disk-usage): concurrently get details (#1326)
This commit is contained in:
@@ -2,14 +2,18 @@ package handles
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/OpenListTeam/OpenList/v4/internal/conf"
|
||||
"github.com/OpenListTeam/OpenList/v4/internal/db"
|
||||
"github.com/OpenListTeam/OpenList/v4/internal/driver"
|
||||
"github.com/OpenListTeam/OpenList/v4/internal/errs"
|
||||
"github.com/OpenListTeam/OpenList/v4/internal/model"
|
||||
"github.com/OpenListTeam/OpenList/v4/internal/op"
|
||||
"github.com/OpenListTeam/OpenList/v4/internal/setting"
|
||||
"github.com/OpenListTeam/OpenList/v4/server/common"
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -28,20 +32,27 @@ func makeStorageResp(c *gin.Context, storages []model.Storage) []*StorageResp {
|
||||
Storage: s,
|
||||
MountDetails: nil,
|
||||
}
|
||||
if setting.GetBool(conf.HideStorageDetailsInManagePage) {
|
||||
continue
|
||||
}
|
||||
d, err := op.GetStorageByMountPath(s.MountPath)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
wd, ok := d.(driver.WithDetails)
|
||||
_, ok := d.(driver.WithDetails)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
details, err := wd.GetDetails(c)
|
||||
ctx, cancel := context.WithTimeout(c, time.Second*3)
|
||||
defer cancel()
|
||||
details, err := op.GetStorageDetails(ctx, d)
|
||||
if err != nil {
|
||||
log.Errorf("failed get %s details: %+v", s.MountPath, err)
|
||||
if !errors.Is(err, errs.NotImplement) {
|
||||
log.Errorf("failed get %s details: %+v", s.MountPath, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
ret[i].MountDetails = details
|
||||
|
||||
Reference in New Issue
Block a user