mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-16 01:00:17 +01:00
downloads: reconcile bulk deletion as one batch
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user