downloads: reconcile bulk deletion as one batch

This commit is contained in:
austinried
2026-11-14 12:05:29 +00:00
parent 35f4f9178b
commit 9514bc501a
3 changed files with 70 additions and 1 deletions
@@ -291,6 +291,17 @@ class DownloadRepository(
}
}
suspend fun remove(
sourceId: Long,
songIds: Collection<String>,
) = withContext(dispatcher) {
val ids = songIds.toHashSet()
mutex.withLock {
removeRows(db.downloadDao().all().filter { it.sourceId == sourceId && it.songId in ids })
sweep(db.downloadDao().all())
}
}
suspend fun cancel(
sourceId: Long,
songIds: Collection<String>,
@@ -78,7 +78,7 @@ class DownloadsViewModel(
fun deleteSongs(songIds: List<String>) {
viewModelScope.launch {
val source = sourceId.first()
songIds.forEach { downloadRepository.remove(source, it) }
downloadRepository.remove(source, songIds)
playbackController.refreshMediaItems()
}
}