Load all tracks in one query for statistics

This commit is contained in:
AntsyLich
2026-10-05 05:54:28 +06:00
parent 5df78e305e
commit 179bfaca72
4 changed files with 18 additions and 3 deletions
@@ -11,6 +11,10 @@ class GetTracksPerManga(
private val trackRepository: TrackRepository,
) {
suspend fun await(): Map<Long, List<Track>> {
return trackRepository.getTracks().groupBy { it.mangaId }
}
fun subscribe(): Flow<Map<Long, List<Track>>> {
return trackRepository.getTracksAsFlow().map { tracks -> tracks.groupBy { it.mangaId } }
}
@@ -9,6 +9,8 @@ interface TrackRepository {
suspend fun getTracksByMangaId(mangaId: Long): List<Track>
suspend fun getTracks(): List<Track>
fun getTracksAsFlow(): Flow<List<Track>>
fun getTracksByMangaIdAsFlow(mangaId: Long): Flow<List<Track>>