feat: keep radio playing when a small library is exhausted
CI / chart (push) Successful in 2s
CI / chart-push (push) Successful in 3s
CI / test (push) Successful in 1m49s
CI / image (push) Successful in 3m14s

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:
TapTap committed 2026-11-14 19:44:20 +00:00
1 parent 13f36daeab
commit 0df1da7cf7
3 files changed
+10 -4

No files matched your search

@@ -123,8 +123,8 @@ class RadioService {
candidates.keys.removeAll(skip)
// When a session has already heard the whole mood, allow controlled replay
// instead of ending with silence.
// Small libraries can exhaust the mood. Replay tracks the session already
// heard instead of returning silence, but never repeat the current batch.
if (candidates.size < limit) {
LibraryRepository.randomSongs(
size = max(limit * 10, 200),
@@ -134,7 +134,7 @@ class RadioService {
folderIds = folders,
userName = user.name,
).forEach { song ->
if (song.id !in skip || sessionSongs.size > 200) {
if (song.id !in excluded) {
candidates.putIfAbsent(song.id, song)
}
}
@@ -180,7 +180,12 @@ class ApiRoutesTest {
assertEquals(HttpStatusCode.OK, second.status)
val nextIds = parse(second.bodyAsText())["songs"]!!.jsonArray
.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") {
bearer(token)