mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-04 04:26:38 +08:00
fix cloud library scale and playback compatibility
Root cause: display-only cloud library filtering was reused by scan jobs, merged cloud mounts could be skipped, and OpenList listing relied on WebDAV/first-page behavior that could cap huge directories around 100 items. Cloud scans also let new items consume probe budget before existing rows with missing track/artwork metadata.\n\nChanges:\n- split display filtering from scannable cloud filtering so merged cloud mounts still scan\n- add OpenList API pagination with WebDAV fallback\n- prioritize existing cloud media missing metadata before new imports\n- restrict automatic cloud sync to one successful 19:00-21:00 daily window and keep manual scan immediate\n- disable startup cloud full-scan by default, with an explicit opt-in setting\n- improve Emby/cloud playback compatibility and cache/search/test coverage from the continued work
This commit is contained in:
@@ -7,21 +7,32 @@ import (
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/ShukeBta/MediaStationGo/internal/model"
|
||||
"github.com/ShukeBta/MediaStationGo/internal/repository"
|
||||
)
|
||||
|
||||
// BootCloudLibraries 在系统启动后自动扫描所有云盘媒体库,使媒体对所有用户立即可见。
|
||||
// 避免每个用户首次访问时都触发扫描。
|
||||
// BootCloudLibraries optionally scans cloud libraries after startup. It is
|
||||
// disabled by default for huge cloud mounts; normal automatic refresh is handled
|
||||
// by the nightly cloud_sync scheduler window, and operators can still scan
|
||||
// manually at any time.
|
||||
func (c *Container) BootCloudLibraries(ctx context.Context) {
|
||||
if c == nil || c.Repo == nil || c.Scan == nil {
|
||||
return
|
||||
}
|
||||
if !bootCloudLibraryScanEnabled(ctx, c.Repo) {
|
||||
c.Log.Info("boot: cloud library scans disabled; use manual scan or nightly cloud sync")
|
||||
return
|
||||
}
|
||||
libs, err := c.Repo.Library.List(ctx)
|
||||
if err != nil {
|
||||
c.Log.Warn("boot cloud libraries: list failed", zap.Error(err))
|
||||
return
|
||||
}
|
||||
libs = FilterScannableCloudLibraries(ctx, c.Repo, libs)
|
||||
cloudLibs := make([]model.Library, 0)
|
||||
for _, lib := range libs {
|
||||
if !lib.Enabled {
|
||||
continue
|
||||
}
|
||||
if _, ok := ParseCloudLibraryMount(lib.Path); ok {
|
||||
cloudLibs = append(cloudLibs, lib)
|
||||
}
|
||||
@@ -32,19 +43,32 @@ func (c *Container) BootCloudLibraries(ctx context.Context) {
|
||||
c.Log.Info("boot: scheduling cloud library scans", zap.Int("count", len(cloudLibs)))
|
||||
// 延迟3秒后启动,避免和系统初始化任务冲突
|
||||
time.AfterFunc(3*time.Second, func() {
|
||||
for _, lib := range cloudLibs {
|
||||
libID := lib.ID
|
||||
libName := lib.Name
|
||||
go func() {
|
||||
scanCtx, cancel := context.WithTimeout(context.Background(), 2*time.Hour)
|
||||
defer cancel()
|
||||
c.Log.Info("boot: scanning cloud library", zap.String("id", libID), zap.String("name", libName))
|
||||
if _, err := c.Scan.ScanLibraryWithoutAutoScrape(scanCtx, libID); err != nil {
|
||||
c.Log.Warn("boot: cloud library scan failed", zap.String("id", libID), zap.String("name", libName), zap.Error(err))
|
||||
} else {
|
||||
c.Log.Info("boot: cloud library scan completed", zap.String("id", libID), zap.String("name", libName))
|
||||
}
|
||||
}()
|
||||
}
|
||||
go c.runBootCloudLibraryScanQueue(cloudLibs)
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Container) runBootCloudLibraryScanQueue(cloudLibs []model.Library) {
|
||||
for _, lib := range cloudLibs {
|
||||
libID := lib.ID
|
||||
libName := lib.Name
|
||||
scanCtx, cancel := context.WithTimeout(context.Background(), 2*time.Hour)
|
||||
c.Log.Info("boot: scanning cloud library", zap.String("id", libID), zap.String("name", libName))
|
||||
if _, err := c.Scan.ScanLibraryWithoutAutoScrape(scanCtx, libID); err != nil {
|
||||
c.Log.Warn("boot: cloud library scan failed", zap.String("id", libID), zap.String("name", libName), zap.Error(err))
|
||||
} else {
|
||||
c.Log.Info("boot: cloud library scan completed", zap.String("id", libID), zap.String("name", libName))
|
||||
}
|
||||
cancel()
|
||||
}
|
||||
}
|
||||
|
||||
func bootCloudLibraryScanEnabled(ctx context.Context, repo *repository.Container) bool {
|
||||
if repo == nil || repo.Setting == nil {
|
||||
return false
|
||||
}
|
||||
value, err := repo.Setting.Get(ctx, "cloud.boot_scan_enabled")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return parseBoolSetting(value, false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user