From f145fd0dec583eff25d993e7f1bfbb0186ce3b93 Mon Sep 17 00:00:00 2001 From: Ken Swenson Date: Sun, 11 Apr 2021 10:49:13 -0400 Subject: [PATCH] Move deletion actions to the IO thread (#4808) --- .../data/download/DownloadManager.kt | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt index 8a5bad025a..596f021892 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt @@ -12,6 +12,7 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.Page +import eu.kanade.tachiyomi.util.lang.launchIO import rx.Observable import timber.log.Timber import uy.kohesive.injekt.injectLazy @@ -211,16 +212,16 @@ class DownloadManager(private val context: Context) { */ fun deleteChapters(chapters: List, manga: Manga, source: Source): List { val filteredChapters = getChaptersToDelete(chapters) + launchIO { + removeFromDownloadQueue(filteredChapters) - removeFromDownloadQueue(filteredChapters) - - val chapterDirs = provider.findChapterDirs(filteredChapters, manga, source) - chapterDirs.forEach { it.delete() } - cache.removeChapters(filteredChapters, manga) - if (cache.getDownloadCount(manga) == 0) { // Delete manga directory if empty - chapterDirs.firstOrNull()?.parentFile?.delete() + val chapterDirs = provider.findChapterDirs(filteredChapters, manga, source) + chapterDirs.forEach { it.delete() } + cache.removeChapters(filteredChapters, manga) + if (cache.getDownloadCount(manga) == 0) { // Delete manga directory if empty + chapterDirs.firstOrNull()?.parentFile?.delete() + } } - return filteredChapters } @@ -249,9 +250,11 @@ class DownloadManager(private val context: Context) { * @param source the source of the manga. */ fun deleteManga(manga: Manga, source: Source) { - downloader.queue.remove(manga) - provider.findMangaDir(manga, source)?.delete() - cache.removeManga(manga) + launchIO { + downloader.queue.remove(manga) + provider.findMangaDir(manga, source)?.delete() + cache.removeManga(manga) + } } /**