Now lastPlayedCache's initial capacity is not hardcoded to 10. And it will be filled slowly, instead of initial read of last N songs from a playlist.log.
This commit is contained in:
parent
47e3ff37ba
commit
db02047268
@ -22,7 +22,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
lastPlayedCache []Song = make([]Song, 10)
|
lastPlayedCache []Song
|
||||||
lastPlayedCacheMutex sync.Mutex
|
lastPlayedCacheMutex sync.Mutex
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -204,8 +204,15 @@ func (pw *PlaylistLogWatcher) Watch(playlistPath string, n int) (err error) {
|
|||||||
case mask := <-pw.changed:
|
case mask := <-pw.changed:
|
||||||
if mask&syscall.IN_MODIFY > 0 {
|
if mask&syscall.IN_MODIFY > 0 {
|
||||||
lastPlayedCacheMutex.Lock()
|
lastPlayedCacheMutex.Lock()
|
||||||
if songs, err := icecastLastPlayedSongs(playlistPath, n); err == nil {
|
if lastPlayedCache == nil {
|
||||||
lastPlayedCache = songs
|
lastPlayedCache = make([]Song, n)
|
||||||
|
}
|
||||||
|
if songs, err := icecastLastPlayedSongs(playlistPath, 1); err == nil && len(songs) > 0 {
|
||||||
|
if len(lastPlayedCache) == n {
|
||||||
|
lastPlayedCache = append(lastPlayedCache[1:], songs...)
|
||||||
|
} else {
|
||||||
|
lastPlayedCache = append(lastPlayedCache, songs...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
lastPlayedCacheMutex.Unlock()
|
lastPlayedCacheMutex.Unlock()
|
||||||
} else if mask&syscall.IN_IGNORED > 0 {
|
} else if mask&syscall.IN_IGNORED > 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user