1
0

Compute lastPlayedCache length once a call.

This commit is contained in:
Alexander Andreev 2022-03-31 18:13:49 +04:00
parent d3563abba1
commit a9b6e5a056
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F

View File

@ -65,19 +65,20 @@ func IcecastGetStatus(icecastURL string) (*IcecastStatus, error) {
} }
func IcecastLastPlayedSongs(lastNSongs int, playlistPath string) ([]Song, error) { func IcecastLastPlayedSongs(lastNSongs int, playlistPath string) ([]Song, error) {
if len(lastPlayedCache) > 0 {
if lastNSongs > len(lastPlayedCache) { if lpcLen := len(lastPlayedCache); lpcLen > 0 {
lastNSongs = len(lastPlayedCache) if lastNSongs > lpcLen {
lastNSongs = lpcLen
} }
return lastPlayedCache[len(lastPlayedCache)-lastNSongs:], nil return lastPlayedCache[lpcLen-lastNSongs:], nil
} }
return lastPlayedSongs(lastNSongs, playlistPath) return lastPlayedSongs(lastNSongs, playlistPath)
} }
func IcecastLastSong(playlistPath string) (Song, error) { func IcecastLastSong(playlistPath string) (Song, error) {
if len(lastPlayedCache) > 0 { if lpcLen := len(lastPlayedCache); lpcLen > 0 {
return lastPlayedCache[len(lastPlayedCache)-1], nil return lastPlayedCache[lpcLen-1], nil
} }
songs, err := lastPlayedSongs(1, playlistPath) songs, err := lastPlayedSongs(1, playlistPath)