1
0

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:
Alexander Andreev 2023-03-12 02:19:07 +04:00
parent 47e3ff37ba
commit db02047268
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -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 {