feat: keep radio playing when a small library is exhausted
A mood with fewer tracks than a batch used to return an empty queue once the session had heard everything. Allow controlled replay of already-heard tracks once no unheard candidates remain, while still never repeating a track inside one batch and never leaving the owner's music folders.
This commit is contained in:
1 parent
13f36daeab
commit
0df1da7cf7
3 files changed
+10
-4
No files matched your search
@@ -23,3 +23,4 @@ test-media/
|
|||||||
|
|
||||||
# Packaged Helm charts
|
# Packaged Helm charts
|
||||||
dist/
|
dist/
|
||||||
|
.kotlin/
|
||||||
@@ -123,8 +123,8 @@ class RadioService {
|
|||||||
|
|
||||||
candidates.keys.removeAll(skip)
|
candidates.keys.removeAll(skip)
|
||||||
|
|
||||||
// When a session has already heard the whole mood, allow controlled replay
|
// Small libraries can exhaust the mood. Replay tracks the session already
|
||||||
// instead of ending with silence.
|
// heard instead of returning silence, but never repeat the current batch.
|
||||||
if (candidates.size < limit) {
|
if (candidates.size < limit) {
|
||||||
LibraryRepository.randomSongs(
|
LibraryRepository.randomSongs(
|
||||||
size = max(limit * 10, 200),
|
size = max(limit * 10, 200),
|
||||||
@@ -134,7 +134,7 @@ class RadioService {
|
|||||||
folderIds = folders,
|
folderIds = folders,
|
||||||
userName = user.name,
|
userName = user.name,
|
||||||
).forEach { song ->
|
).forEach { song ->
|
||||||
if (song.id !in skip || sessionSongs.size > 200) {
|
if (song.id !in excluded) {
|
||||||
candidates.putIfAbsent(song.id, song)
|
candidates.putIfAbsent(song.id, song)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,7 +180,12 @@ class ApiRoutesTest {
|
|||||||
assertEquals(HttpStatusCode.OK, second.status)
|
assertEquals(HttpStatusCode.OK, second.status)
|
||||||
val nextIds = parse(second.bodyAsText())["songs"]!!.jsonArray
|
val nextIds = parse(second.bodyAsText())["songs"]!!.jsonArray
|
||||||
.map { it.jsonObject.string("id") }
|
.map { it.jsonObject.string("id") }
|
||||||
assertTrue(nextIds.none { it in queue.map { song -> song.string("id") } })
|
// The test library is smaller than the batch, so the session has
|
||||||
|
// already heard everything. Replay is allowed, duplicates in one
|
||||||
|
// batch are not, and non-music folders still never appear.
|
||||||
|
assertTrue(nextIds.isNotEmpty())
|
||||||
|
assertEquals(nextIds.size, nextIds.distinct().size)
|
||||||
|
assertTrue(nextIds.none { it == seed.longformSong || it == seed.bobSong })
|
||||||
|
|
||||||
val completed = client.post("/api/v1/sessions/$sessionId/events") {
|
val completed = client.post("/api/v1/sessions/$sessionId/events") {
|
||||||
bearer(token)
|
bearer(token)
|
||||||
|
|||||||
Reference in new issue
Block a user