diff --git a/app/src/main/java/eu/kanade/data/category/CategoryRepositoryImpl.kt b/app/src/main/java/eu/kanade/data/category/CategoryRepositoryImpl.kt index 49be1bae7..cfbd2eb64 100644 --- a/app/src/main/java/eu/kanade/data/category/CategoryRepositoryImpl.kt +++ b/app/src/main/java/eu/kanade/data/category/CategoryRepositoryImpl.kt @@ -52,7 +52,7 @@ class CategoryRepositoryImpl( } override suspend fun updatePartial(updates: List) { - handler.await(true) { + handler.await(inTransaction = true) { for (update in updates) { updatePartialBlocking(update) } diff --git a/app/src/main/java/eu/kanade/data/manga/MangaRepositoryImpl.kt b/app/src/main/java/eu/kanade/data/manga/MangaRepositoryImpl.kt index 650331167..9fcb8f79d 100644 --- a/app/src/main/java/eu/kanade/data/manga/MangaRepositoryImpl.kt +++ b/app/src/main/java/eu/kanade/data/manga/MangaRepositoryImpl.kt @@ -74,7 +74,7 @@ class MangaRepositoryImpl( } override suspend fun insert(manga: Manga): Long? { - return handler.awaitOneOrNull { + return handler.awaitOneOrNull(inTransaction = true) { mangasQueries.insert( source = manga.source, url = manga.url, diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt index 9523d9ffc..4868d8d6f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt @@ -205,7 +205,7 @@ class DownloadCache( fun removeManga(manga: Manga) { val sourceDir = rootDownloadsDir.sourceDirs[manga.source] ?: return val mangaDirName = provider.getMangaDirName(manga.title) - if (mangaDirName in sourceDir.mangaDirs) { + if (sourceDir.mangaDirs.containsKey(mangaDirName)) { sourceDir.mangaDirs -= mangaDirName } @@ -271,9 +271,8 @@ class DownloadCache( val mangaDirs = sourceDir.dir.listFiles().orEmpty() .filterNot { it.name.isNullOrBlank() } .associate { it.name!! to MangaDirectory(it) } - .toMutableMap() - sourceDir.mangaDirs = mangaDirs + sourceDir.mangaDirs = ConcurrentHashMap(mangaDirs) mangaDirs.values.forEach { mangaDir -> val chapterDirs = mangaDir.dir.listFiles().orEmpty() @@ -308,7 +307,7 @@ class DownloadCache( /** * Returns a new map containing only the key entries of [transform] that are not null. */ - private inline fun Map.mapNotNullKeys(transform: (Map.Entry) -> R?): MutableMap { + private inline fun Map.mapNotNullKeys(transform: (Map.Entry) -> R?): ConcurrentHashMap { val mutableMap = ConcurrentHashMap() forEach { element -> transform(element)?.let { mutableMap[it] = element.value } } return mutableMap @@ -320,7 +319,7 @@ class DownloadCache( */ private class RootDirectory( val dir: UniFile, - var sourceDirs: MutableMap = mutableMapOf(), + var sourceDirs: ConcurrentHashMap = ConcurrentHashMap(), ) /** @@ -328,7 +327,7 @@ private class RootDirectory( */ private class SourceDirectory( val dir: UniFile, - var mangaDirs: MutableMap = mutableMapOf(), + var mangaDirs: ConcurrentHashMap = ConcurrentHashMap(), ) /**