Fix freezing on migrating manga (#7317)

* Use `supend` instead of `runBlocking` in migrate function

* lift `syncChaptersWithSource` out of the db trasaction
This commit is contained in:
jmir1 2022-06-17 05:34:44 +02:00 committed by GitHub
parent 4ef337f1e9
commit 6aee4fc464
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 12 deletions

View File

@ -85,7 +85,7 @@ class SearchPresenter(
} }
} }
private fun migrateMangaInternal( private suspend fun migrateMangaInternal(
prevSource: Source?, prevSource: Source?,
source: Source, source: Source,
sourceChapters: List<SChapter>, sourceChapters: List<SChapter>,
@ -111,15 +111,15 @@ class SearchPresenter(
flags, flags,
) )
db.inTransaction {
// Update chapters read
if (migrateChapters) {
try { try {
syncChaptersWithSource(sourceChapters, manga, source) syncChaptersWithSource(sourceChapters, manga, source)
} catch (e: Exception) { } catch (e: Exception) {
// Worst case, chapters won't be synced // Worst case, chapters won't be synced
} }
db.inTransaction {
// Update chapters read
if (migrateChapters) {
val prevMangaChapters = db.getChapters(prevManga).executeAsBlocking() val prevMangaChapters = db.getChapters(prevManga).executeAsBlocking()
val maxChapterRead = prevMangaChapters val maxChapterRead = prevMangaChapters
.filter { it.read } .filter { it.read }

View File

@ -5,7 +5,6 @@ import eu.kanade.domain.chapter.model.toDbChapter
import eu.kanade.tachiyomi.data.database.models.toDomainManga import eu.kanade.tachiyomi.data.database.models.toDomainManga
import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SChapter
import kotlinx.coroutines.runBlocking
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import eu.kanade.tachiyomi.data.database.models.Chapter as DbChapter import eu.kanade.tachiyomi.data.database.models.Chapter as DbChapter
@ -19,16 +18,14 @@ import eu.kanade.tachiyomi.data.database.models.Manga as DbManga
* @param source the source of the chapters. * @param source the source of the chapters.
* @return a pair of new insertions and deletions. * @return a pair of new insertions and deletions.
*/ */
fun syncChaptersWithSource( suspend fun syncChaptersWithSource(
rawSourceChapters: List<SChapter>, rawSourceChapters: List<SChapter>,
manga: DbManga, manga: DbManga,
source: Source, source: Source,
syncChaptersWithSource: SyncChaptersWithSource = Injekt.get(), syncChaptersWithSource: SyncChaptersWithSource = Injekt.get(),
): Pair<List<DbChapter>, List<DbChapter>> { ): Pair<List<DbChapter>, List<DbChapter>> {
val domainManga = manga.toDomainManga() ?: return Pair(emptyList(), emptyList()) val domainManga = manga.toDomainManga() ?: return Pair(emptyList(), emptyList())
val (added, deleted) = runBlocking { val (added, deleted) = syncChaptersWithSource.await(rawSourceChapters, domainManga, source)
syncChaptersWithSource.await(rawSourceChapters, domainManga, source)
}
val addedDbChapters = added.map { it.toDbChapter() } val addedDbChapters = added.map { it.toDbChapter() }
val deletedDbChapters = deleted.map { it.toDbChapter() } val deletedDbChapters = deleted.map { it.toDbChapter() }