mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Avoid some crashes
This commit is contained in:
parent
3fb42b6ce9
commit
ca06516900
3 changed files with 7 additions and 8 deletions
|
@ -52,7 +52,7 @@ class CategoryRepositoryImpl(
|
|||
}
|
||||
|
||||
override suspend fun updatePartial(updates: List<CategoryUpdate>) {
|
||||
handler.await(true) {
|
||||
handler.await(inTransaction = true) {
|
||||
for (update in updates) {
|
||||
updatePartialBlocking(update)
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 <K, V, R> Map<out K, V>.mapNotNullKeys(transform: (Map.Entry<K?, V>) -> R?): MutableMap<R, V> {
|
||||
private inline fun <K, V, R> Map<out K, V>.mapNotNullKeys(transform: (Map.Entry<K?, V>) -> R?): ConcurrentHashMap<R, V> {
|
||||
val mutableMap = ConcurrentHashMap<R, V>()
|
||||
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<Long, SourceDirectory> = mutableMapOf(),
|
||||
var sourceDirs: ConcurrentHashMap<Long, SourceDirectory> = ConcurrentHashMap(),
|
||||
)
|
||||
|
||||
/**
|
||||
|
@ -328,7 +327,7 @@ private class RootDirectory(
|
|||
*/
|
||||
private class SourceDirectory(
|
||||
val dir: UniFile,
|
||||
var mangaDirs: MutableMap<String, MangaDirectory> = mutableMapOf(),
|
||||
var mangaDirs: ConcurrentHashMap<String, MangaDirectory> = ConcurrentHashMap(),
|
||||
)
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue