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,42 +80,27 @@ 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 {
if lastNSongs > lpcLen {
lastNSongs = lpcLen
}
var ret []Song = make([]Song, lastNSongs)
copy(ret[:], lastPlayedCache[lpcLen-lastNSongs:])
return ret, nil
lastPlayedCacheMutex.Lock()
defer lastPlayedCacheMutex.Unlock()
if lpcLen := len(lastPlayedCache); lpcLen > 0 {
if lastNSongs > lpcLen {
lastNSongs = lpcLen
}
var ret []Song = make([]Song, lastNSongs)
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) {
{
lastPlayedCacheMutex.Lock()
defer lastPlayedCacheMutex.Unlock()
if lpcLen := len(lastPlayedCache); lpcLen > 0 {
return lastPlayedCache[lpcLen-1], nil
}
func IcecastLastSong(playlistPath string) (*Song, error) {
lastPlayedCacheMutex.Lock()
defer lastPlayedCacheMutex.Unlock()
if lpcLen := len(lastPlayedCache); lpcLen > 0 {
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,20 +191,20 @@ func (pw *PlaylistLogWatcher) Watch(playlistPath string, n int) (err error) {
if mask&syscall.IN_MODIFY > 0 {
if isJustStarted {
isJustStarted = false
break
}
lastPlayedCacheMutex.Lock()
if lastPlayedCache == nil {
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...)
} else {
lastPlayedCacheMutex.Lock()
if lastPlayedCache == nil {
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 {
pw.Close()
pw.Watch(playlistPath, n)