1
0

Oh, last commit led to loading of full list of prev songs. Let's remove this code.

This commit is contained in:
Alexander Andreev 2023-03-12 04:01:32 +04:00
parent 10048c671e
commit 0409da3ca3
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -80,7 +80,6 @@ func IcecastGetStatus(icecastURL string) (*IcecastStatus, error) {
}
func IcecastLastPlayedSongs(lastNSongs int, playlistPath string) ([]Song, error) {
{
lastPlayedCacheMutex.Lock()
defer lastPlayedCacheMutex.Unlock()
if lpcLen := len(lastPlayedCache); lpcLen > 0 {
@ -91,31 +90,17 @@ func IcecastLastPlayedSongs(lastNSongs int, playlistPath string) ([]Song, error)
copy(ret[:], lastPlayedCache[lpcLen-lastNSongs:])
return ret, nil
}
}
songs, err := icecastLastPlayedSongs(playlistPath, lastNSongs)
if err != nil {
return make([]Song, 0), err
}
return songs, nil
return nil, nil
}
func IcecastLastSong(playlistPath string) (Song, error) {
{
func IcecastLastSong(playlistPath string) (*Song, error) {
lastPlayedCacheMutex.Lock()
defer lastPlayedCacheMutex.Unlock()
if lpcLen := len(lastPlayedCache); lpcLen > 0 {
return lastPlayedCache[lpcLen-1], nil
return &lastPlayedCache[lpcLen-1], nil
}
}
song, err := icecastLastPlayedSongs(playlistPath, 1)
if err != nil {
return Song{}, err
}
return song[0], nil
return nil, nil
}
func icecastLastPlayedSongs(playlistPath string, n int) ([]Song, error) {
@ -206,8 +191,7 @@ func (pw *PlaylistLogWatcher) Watch(playlistPath string, n int) (err error) {
if mask&syscall.IN_MODIFY > 0 {
if isJustStarted {
isJustStarted = false
break
}
} else {
lastPlayedCacheMutex.Lock()
if lastPlayedCache == nil {
lastPlayedCache = make([]Song, n)
@ -220,6 +204,7 @@ func (pw *PlaylistLogWatcher) Watch(playlistPath string, n int) (err error) {
}
}
lastPlayedCacheMutex.Unlock()
}
} else if mask&syscall.IN_IGNORED > 0 {
pw.Close()
pw.Watch(playlistPath, n)