Compute lastPlayedCache length once a call.
This commit is contained in:
parent
d3563abba1
commit
a9b6e5a056
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user