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