feat(scanner): add library stats to DB (#4229)
* Combine library stats migrations * test: verify full library stats * Fix total_songs calculation * Fix library stats migration * fix(scanner): log elapsed time and number of libraries updated during scan Signed-off-by: Deluan <deluan@navidrome.org> * fix(scanner): refresh library stats conditionally, only if changes were detected Signed-off-by: Deluan <deluan@navidrome.org> * fix(scanner): refresh library stats conditionally, only if changes were detected Signed-off-by: Deluan <deluan@navidrome.org> * fix(scanner): update queries to exclude missing entries in library stats Signed-off-by: Deluan <deluan@navidrome.org> --------- Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
+6
-13
@@ -7,7 +7,6 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/navidrome/navidrome/conf"
|
||||
"github.com/navidrome/navidrome/consts"
|
||||
"github.com/navidrome/navidrome/core"
|
||||
@@ -178,20 +177,14 @@ func (s *controller) Status(ctx context.Context) (*StatusInfo, error) {
|
||||
}
|
||||
|
||||
func (s *controller) getCounters(ctx context.Context) (int64, int64, error) {
|
||||
count, err := s.ds.MediaFile(ctx).CountAll()
|
||||
libs, err := s.ds.Library(ctx).GetAll()
|
||||
if err != nil {
|
||||
return 0, 0, fmt.Errorf("media file count: %w", err)
|
||||
return 0, 0, fmt.Errorf("library count: %w", err)
|
||||
}
|
||||
folderCount, err := s.ds.Folder(ctx).CountAll(
|
||||
model.QueryOptions{
|
||||
Filters: squirrel.And{
|
||||
squirrel.Gt{"num_audio_files": 0},
|
||||
squirrel.Eq{"missing": false},
|
||||
},
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return 0, 0, fmt.Errorf("folder count: %w", err)
|
||||
var count, folderCount int64
|
||||
for _, l := range libs {
|
||||
count += int64(l.TotalSongs)
|
||||
folderCount += int64(l.TotalFolders)
|
||||
}
|
||||
return count, folderCount, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user