Show folders scanned instead of files scanned

This commit is contained in:
Deluan 2020-11-16 00:33:17 -05:00
parent be715c3696
commit a1dcb9a4e3
11 changed files with 60 additions and 30 deletions

View file

@ -6,7 +6,6 @@ import (
"fmt" "fmt"
"strconv" "strconv"
"sync" "sync"
"sync/atomic"
"time" "time"
"github.com/deluan/navidrome/core" "github.com/deluan/navidrome/core"
@ -29,6 +28,7 @@ type StatusInfo struct {
Scanning bool Scanning bool
LastScan time.Time LastScan time.Time
Count uint32 Count uint32
FolderCount uint32
} }
var ( var (
@ -54,9 +54,10 @@ type scanner struct {
} }
type scanStatus struct { type scanStatus struct {
active bool active bool
count uint32 fileCount uint32
lastUpdate time.Time folderCount uint32
lastUpdate time.Time
} }
func New(ds model.DataStore, cacheWarmer core.CacheWarmer, broker events.Broker) Scanner { func New(ds model.DataStore, cacheWarmer core.CacheWarmer, broker events.Broker) Scanner {
@ -125,9 +126,13 @@ func (s *scanner) rescan(mediaFolder string, fullRescan bool) error {
func (s *scanner) startProgressTracker(mediaFolder string) chan uint32 { func (s *scanner) startProgressTracker(mediaFolder string) chan uint32 {
progress := make(chan uint32, 100) progress := make(chan uint32, 100)
go func() { go func() {
s.broker.SendMessage(&events.ScanStatus{Scanning: true, Count: 0}) s.broker.SendMessage(&events.ScanStatus{Scanning: true, Count: 0, FolderCount: 0})
defer func() { defer func() {
s.broker.SendMessage(&events.ScanStatus{Scanning: false, Count: int64(s.status[mediaFolder].count)}) s.broker.SendMessage(&events.ScanStatus{
Scanning: false,
Count: int64(s.status[mediaFolder].fileCount),
FolderCount: int64(s.status[mediaFolder].folderCount),
})
}() }()
for { for {
count, more := <-progress count, more := <-progress
@ -137,8 +142,12 @@ func (s *scanner) startProgressTracker(mediaFolder string) chan uint32 {
if count == 0 { if count == 0 {
continue continue
} }
total := atomic.AddUint32(&s.status[mediaFolder].count, count) totalFolders, totalFiles := s.incStatusCounter(mediaFolder, count)
s.broker.SendMessage(&events.ScanStatus{Scanning: true, Count: int64(total)}) s.broker.SendMessage(&events.ScanStatus{
Scanning: true,
Count: int64(totalFiles),
FolderCount: int64(totalFolders),
})
} }
}() }()
return progress return progress
@ -174,12 +183,25 @@ func (s *scanner) getStatus(folder string) *scanStatus {
return nil return nil
} }
func (s *scanner) incStatusCounter(folder string, numFiles uint32) (totalFolders uint32, totalFiles uint32) {
s.lock.Lock()
defer s.lock.Unlock()
if status, ok := s.status[folder]; ok {
status.fileCount += numFiles
status.folderCount++
totalFolders = status.folderCount
totalFiles = status.fileCount
}
return
}
func (s *scanner) setStatusStart(folder string) { func (s *scanner) setStatusStart(folder string) {
s.lock.Lock() s.lock.Lock()
defer s.lock.Unlock() defer s.lock.Unlock()
if status, ok := s.status[folder]; ok { if status, ok := s.status[folder]; ok {
status.active = true status.active = true
status.count = 0 status.fileCount = 0
status.folderCount = 0
} }
} }
@ -205,7 +227,8 @@ func (s *scanner) Status(mediaFolder string) (*StatusInfo, error) {
MediaFolder: mediaFolder, MediaFolder: mediaFolder,
Scanning: status.active, Scanning: status.active,
LastScan: status.lastUpdate, LastScan: status.lastUpdate,
Count: status.count, Count: status.fileCount,
FolderCount: status.folderCount,
}, nil }, nil
} }
@ -234,9 +257,10 @@ func (s *scanner) loadFolders() {
log.Info("Configuring Media Folder", "name", f.Name, "path", f.Path) log.Info("Configuring Media Folder", "name", f.Name, "path", f.Path)
s.folders[f.Path] = s.newScanner(f) s.folders[f.Path] = s.newScanner(f)
s.status[f.Path] = &scanStatus{ s.status[f.Path] = &scanStatus{
active: false, active: false,
count: 0, fileCount: 0,
lastUpdate: s.getLastModifiedSince(f.Path), folderCount: 0,
lastUpdate: s.getLastModifiedSince(f.Path),
} }
} }
} }

View file

@ -7,8 +7,9 @@ type Event interface {
} }
type ScanStatus struct { type ScanStatus struct {
Scanning bool `json:"scanning"` Scanning bool `json:"scanning"`
Count int64 `json:"count"` Count int64 `json:"count"`
FolderCount int64 `json:"folderCount"`
} }
func (s ScanStatus) EventName() string { return "scanStatus" } func (s ScanStatus) EventName() string { return "scanStatus" }

View file

@ -30,9 +30,10 @@ func (c *LibraryScanningController) GetScanStatus(w http.ResponseWriter, r *http
} }
response := newResponse() response := newResponse()
response.ScanStatus = &responses.ScanStatus{ response.ScanStatus = &responses.ScanStatus{
Scanning: status.Scanning, Scanning: status.Scanning,
Count: int64(status.Count), Count: int64(status.Count),
LastScan: &status.LastScan, FolderCount: int64(status.FolderCount),
LastScan: &status.LastScan,
} }
return response, nil return response, nil
} }

View file

@ -1 +1 @@
{"status":"ok","version":"1.8.0","type":"navidrome","serverVersion":"v0.0.0","scanStatus":{"scanning":true,"count":123,"lastScan":"2006-01-02T15:04:00Z"}} {"status":"ok","version":"1.8.0","type":"navidrome","serverVersion":"v0.0.0","scanStatus":{"scanning":true,"count":456,"folderCount":123,"lastScan":"2006-01-02T15:04:00Z"}}

View file

@ -1 +1 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0" type="navidrome" serverVersion="v0.0.0"><scanStatus scanning="true" count="123" lastScan="2006-01-02T15:04:00Z"></scanStatus></subsonic-response> <subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0" type="navidrome" serverVersion="v0.0.0"><scanStatus scanning="true" count="456" folderCount="123" lastScan="2006-01-02T15:04:00Z"></scanStatus></subsonic-response>

View file

@ -1 +1 @@
{"status":"ok","version":"1.8.0","type":"navidrome","serverVersion":"v0.0.0","scanStatus":{"scanning":false,"count":0}} {"status":"ok","version":"1.8.0","type":"navidrome","serverVersion":"v0.0.0","scanStatus":{"scanning":false,"count":0,"folderCount":0}}

View file

@ -1 +1 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0" type="navidrome" serverVersion="v0.0.0"><scanStatus scanning="false" count="0"></scanStatus></subsonic-response> <subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0" type="navidrome" serverVersion="v0.0.0"><scanStatus scanning="false" count="0" folderCount="0"></scanStatus></subsonic-response>

View file

@ -341,7 +341,8 @@ type Bookmarks struct {
} }
type ScanStatus struct { type ScanStatus struct {
Scanning bool `xml:"scanning,attr" json:"scanning"` Scanning bool `xml:"scanning,attr" json:"scanning"`
Count int64 `xml:"count,attr" json:"count"` Count int64 `xml:"count,attr" json:"count"`
LastScan *time.Time `xml:"lastScan,attr,omitempty" json:"lastScan,omitempty"` FolderCount int64 `xml:"folderCount,attr" json:"folderCount"`
LastScan *time.Time `xml:"lastScan,attr,omitempty" json:"lastScan,omitempty"`
} }

View file

@ -546,9 +546,10 @@ var _ = Describe("Responses", func() {
BeforeEach(func() { BeforeEach(func() {
t, _ := time.Parse(time.RFC822, time.RFC822) t, _ := time.Parse(time.RFC822, time.RFC822)
response.ScanStatus = &ScanStatus{ response.ScanStatus = &ScanStatus{
Scanning: true, Scanning: true,
Count: 123, FolderCount: 123,
LastScan: &t, Count: 456,
LastScan: &t,
} }
}) })
It("should match .XML", func() { It("should match .XML", func() {

View file

@ -127,7 +127,7 @@ const ActivityPanel = () => {
{translate('activity.totalScanned')}: {translate('activity.totalScanned')}:
</Box> </Box>
<Box component="span" flex={1}> <Box component="span" flex={1}>
{scanStatus.count} {scanStatus.folderCount || '-'}
</Box> </Box>
</Box> </Box>
</CardContent> </CardContent>

View file

@ -1,6 +1,8 @@
import { EVENT_SCAN_STATUS, EVENT_SERVER_START } from '../actions' import { EVENT_SCAN_STATUS, EVENT_SERVER_START } from '../actions'
const defaultState = { scanStatus: { scanning: false, count: 0 } } const defaultState = {
scanStatus: { scanning: false, folderCount: 0, count: 0 },
}
export const activityReducer = ( export const activityReducer = (
previousState = { previousState = {