From d48972caa003698f3eb02b7d2b75e7bed86f2de7 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sun, 12 Mar 2023 21:48:01 +0400 Subject: [PATCH] Okay, now let's return original idea of adding songs one by one. --- internal/radio/icecast.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/internal/radio/icecast.go b/internal/radio/icecast.go index c6ce53c..9deb94e 100644 --- a/internal/radio/icecast.go +++ b/internal/radio/icecast.go @@ -181,10 +181,7 @@ func (pw *PlaylistLogWatcher) Watch(playlistPath string, n int) (err error) { pw.watcher.WatchForMask(pw.changed, watcher.ModIgnMask) - lastPlayedCache, err = icecastLastPlayedSongs(playlistPath, n) - if err != nil { - return errors.Wrap(err, "cannot instantiate last played cache") - } + lastPlayedCache = make([]Song, 0, n) go func() { for { @@ -192,8 +189,12 @@ func (pw *PlaylistLogWatcher) Watch(playlistPath string, n int) (err error) { case mask := <-pw.changed: if mask&syscall.IN_MODIFY > 0 { lastPlayedCacheMutex.Lock() - if songs, err := icecastLastPlayedSongs(playlistPath, n); err == nil && len(songs) > 0 { - lastPlayedCache = songs + 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() } else if mask&syscall.IN_IGNORED > 0 {