Fix E-H Sync favorites getting stuck

This commit is contained in:
Jobobby04 2020-11-08 15:02:26 -05:00
parent a4e05f297c
commit 89a20be7ef
2 changed files with 11 additions and 10 deletions

View File

@ -10,9 +10,9 @@ import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.online.UrlImportableSource import eu.kanade.tachiyomi.source.online.UrlImportableSource
import eu.kanade.tachiyomi.source.online.all.EHentai import eu.kanade.tachiyomi.source.online.all.EHentai
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource
import eu.kanade.tachiyomi.util.lang.await
import eu.kanade.tachiyomi.util.lang.awaitSingle import eu.kanade.tachiyomi.util.lang.awaitSingle
import exh.source.getMainSource import exh.source.getMainSource
import exh.util.executeOnIO
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
class GalleryAdder { class GalleryAdder {
@ -85,7 +85,7 @@ class GalleryAdder {
} ?: return GalleryAddEvent.Fail.UnknownType(url, context) } ?: return GalleryAddEvent.Fail.UnknownType(url, context)
// Use manga in DB if possible, otherwise, make a new manga // Use manga in DB if possible, otherwise, make a new manga
val manga = db.getManga(cleanedUrl, source.id).await() val manga = db.getManga(cleanedUrl, source.id).executeOnIO()
?: Manga.create(source.id).apply { ?: Manga.create(source.id).apply {
this.url = cleanedUrl this.url = cleanedUrl
title = realUrl title = realUrl
@ -94,7 +94,7 @@ class GalleryAdder {
// Insert created manga if not in DB before fetching details // Insert created manga if not in DB before fetching details
// This allows us to keep the metadata when fetching details // This allows us to keep the metadata when fetching details
if (manga.id == null) { if (manga.id == null) {
db.insertManga(manga).await().insertedId()?.let { db.insertManga(manga).executeOnIO().insertedId()?.let {
manga.id = it manga.id = it
} }
} }
@ -109,7 +109,7 @@ class GalleryAdder {
manga.date_added = System.currentTimeMillis() manga.date_added = System.currentTimeMillis()
} }
db.insertManga(manga).await() db.insertManga(manga).executeOnIO()
// Fetch and copy chapters // Fetch and copy chapters
try { try {

View File

@ -23,6 +23,7 @@ import exh.GalleryAddEvent
import exh.GalleryAdder import exh.GalleryAdder
import exh.eh.EHentaiThrottleManager import exh.eh.EHentaiThrottleManager
import exh.eh.EHentaiUpdateWorker import exh.eh.EHentaiUpdateWorker
import exh.util.executeOnIO
import exh.util.ignore import exh.util.ignore
import exh.util.trans import exh.util.trans
import exh.util.wifiManager import exh.util.wifiManager
@ -194,7 +195,7 @@ class FavoritesSyncHelper(val context: Context) {
} }
private suspend fun applyRemoteCategories(categories: List<String>) { private suspend fun applyRemoteCategories(categories: List<String>) {
val localCategories = db.getCategories().await() val localCategories = db.getCategories().executeOnIO()
val newLocalCategories = localCategories.toMutableList() val newLocalCategories = localCategories.toMutableList()
@ -232,7 +233,7 @@ class FavoritesSyncHelper(val context: Context) {
// Only insert categories if changed // Only insert categories if changed
if (changed) { if (changed) {
db.insertCategories(newLocalCategories).await() db.insertCategories(newLocalCategories).executeOnIO()
} }
} }
@ -343,12 +344,12 @@ class FavoritesSyncHelper(val context: Context) {
db.getManga(url, EXH_SOURCE_ID), db.getManga(url, EXH_SOURCE_ID),
db.getManga(url, EH_SOURCE_ID) db.getManga(url, EH_SOURCE_ID)
).forEach { ).forEach {
val manga = it.await() val manga = it.executeOnIO()
if (manga?.favorite == true) { if (manga?.favorite == true) {
manga.favorite = false manga.favorite = false
manga.date_added = 0 manga.date_added = 0
db.updateMangaFavorite(manga).await() db.updateMangaFavorite(manga).executeOnIO()
removedManga += manga removedManga += manga
} }
} }
@ -356,11 +357,11 @@ class FavoritesSyncHelper(val context: Context) {
// Can't do too many DB OPs in one go // Can't do too many DB OPs in one go
removedManga.chunked(10).forEach { removedManga.chunked(10).forEach {
db.deleteOldMangasCategories(it).await() db.deleteOldMangasCategories(it).executeAsBlocking()
} }
val insertedMangaCategories = mutableListOf<Pair<MangaCategory, Manga>>() val insertedMangaCategories = mutableListOf<Pair<MangaCategory, Manga>>()
val categories = db.getCategories().await() val categories = db.getCategories().executeOnIO()
// Apply additions // Apply additions
throttleManager.resetThrottle() throttleManager.resetThrottle()