fix: avoid duplicate beat metadata fetching from api

This commit is contained in:
2026-05-31 12:02:28 +02:00
parent 19bbccf244
commit a10102c10a
3 changed files with 16 additions and 10 deletions

View File

@@ -23,6 +23,8 @@
## Nice-to ## Nice-to
- beat metadata is handled by the app, currently. The handling should move into "jukebox".
- add a test for /playlists/<playlist_id> but obfuscate the IDs and user id - add a test for /playlists/<playlist_id> but obfuscate the IDs and user id
- TrackFileMatching, scoreAgainstLocalHints - TrackFileMatching, scoreAgainstLocalHints

View File

@@ -91,17 +91,21 @@ fun AnnotationRoute(
var playlistDisplayName by remember { mutableStateOf("playlist") } var playlistDisplayName by remember { mutableStateOf("playlist") }
LaunchedEffect(playlistId) { LaunchedEffect(playlistId) {
playlistDisplayName = viewModel.getPlaylistDisplayName(playlistId) val name = viewModel.getPlaylistDisplayName(playlistId)
playlistDisplayName = name
viewModel.fetchBeatsMetadataForPlaylist(playlistId, name)
} }
LaunchedEffect(playback, playlistId, playlistDisplayName, annotationSessionFolder) { LaunchedEffect(playback, playlistId, annotationSessionFolder) {
val service = playback ?: return@LaunchedEffect val service = playback ?: return@LaunchedEffect
val name = viewModel.getPlaylistDisplayName(playlistId)
playlistDisplayName = name
service.trackBoundaryEvents.collect { event -> service.trackBoundaryEvents.collect { event ->
val snapshot = beatTimesMs.toList() val snapshot = beatTimesMs.toList()
beatTimesMs.clear() beatTimesMs.clear()
viewModel.persistBeatAnnotation( viewModel.persistBeatAnnotation(
playlistId, playlistId,
playlistDisplayName, name,
annotationSessionFolder, annotationSessionFolder,
event, event,
snapshot, snapshot,

View File

@@ -212,11 +212,9 @@ fun NowPlayingRoute(
} }
LaunchedEffect(playlistId) { LaunchedEffect(playlistId) {
playlistDisplayName = viewModel.getPlaylistDisplayName(playlistId) val name = viewModel.getPlaylistDisplayName(playlistId)
} playlistDisplayName = name
viewModel.fetchBeatsMetadataForPlaylist(playlistId, name)
LaunchedEffect(playlistId, playlistDisplayName) {
viewModel.fetchBeatsMetadataForPlaylist(playlistId, playlistDisplayName)
} }
LaunchedEffect(playback) { LaunchedEffect(playback) {
@@ -257,12 +255,14 @@ fun NowPlayingRoute(
} }
} }
LaunchedEffect(collectRunData, playback, playlistId, playlistDisplayName) { LaunchedEffect(collectRunData, playback, playlistId) {
if (!collectRunData) return@LaunchedEffect if (!collectRunData) return@LaunchedEffect
val service = playback ?: return@LaunchedEffect val service = playback ?: return@LaunchedEffect
val name = viewModel.getPlaylistDisplayName(playlistId)
playlistDisplayName = name
service.trackBoundaryEvents.collect { event -> service.trackBoundaryEvents.collect { event ->
val snapshot = collector.snapshotAndClear() val snapshot = collector.snapshotAndClear()
viewModel.persistRunData(playlistId, playlistDisplayName, runSessionFolder, event, snapshot) viewModel.persistRunData(playlistId, name, runSessionFolder, event, snapshot)
} }
} }