From 0df1da7cf7ee388b9933b88df9459023accb1ce0 Mon Sep 17 00:00:00 2001 From: TapTap Date: Sat, 14 Nov 2026 19:44:20 +0000 Subject: [PATCH] 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. --- .gitignore | 1 + .../kotlin/win/taptap/musicmanager/radio/RadioService.kt | 6 +++--- .../kotlin/win/taptap/musicmanager/api/ApiRoutesTest.kt | 7 ++++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 71c6698..e87ae2a 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ test-media/ # Packaged Helm charts dist/ +.kotlin/ diff --git a/src/main/kotlin/win/taptap/musicmanager/radio/RadioService.kt b/src/main/kotlin/win/taptap/musicmanager/radio/RadioService.kt index 9c71cc8..0abc2ec 100644 --- a/src/main/kotlin/win/taptap/musicmanager/radio/RadioService.kt +++ b/src/main/kotlin/win/taptap/musicmanager/radio/RadioService.kt @@ -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) } } diff --git a/src/test/kotlin/win/taptap/musicmanager/api/ApiRoutesTest.kt b/src/test/kotlin/win/taptap/musicmanager/api/ApiRoutesTest.kt index 0551fe8..e638e65 100644 --- a/src/test/kotlin/win/taptap/musicmanager/api/ApiRoutesTest.kt +++ b/src/test/kotlin/win/taptap/musicmanager/api/ApiRoutesTest.kt @@ -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)