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

View file

@ -7,8 +7,9 @@ type Event interface {
}
type ScanStatus struct {
Scanning bool `json:"scanning"`
Count int64 `json:"count"`
Scanning bool `json:"scanning"`
Count int64 `json:"count"`
FolderCount int64 `json:"folderCount"`
}
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.ScanStatus = &responses.ScanStatus{
Scanning: status.Scanning,
Count: int64(status.Count),
LastScan: &status.LastScan,
Scanning: status.Scanning,
Count: int64(status.Count),
FolderCount: int64(status.FolderCount),
LastScan: &status.LastScan,
}
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 {
Scanning bool `xml:"scanning,attr" json:"scanning"`
Count int64 `xml:"count,attr" json:"count"`
LastScan *time.Time `xml:"lastScan,attr,omitempty" json:"lastScan,omitempty"`
Scanning bool `xml:"scanning,attr" json:"scanning"`
Count int64 `xml:"count,attr" json:"count"`
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() {
t, _ := time.Parse(time.RFC822, time.RFC822)
response.ScanStatus = &ScanStatus{
Scanning: true,
Count: 123,
LastScan: &t,
Scanning: true,
FolderCount: 123,
Count: 456,
LastScan: &t,
}
})
It("should match .XML", func() {

View file

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

View file

@ -1,6 +1,8 @@
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 = (
previousState = {