mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-03 19:04:39 -05:00
Simplify fetching manga and chapters
This commit is contained in:
@@ -26,6 +26,7 @@ import suwayomi.tachidesk.graphql.types.ChapterType
|
|||||||
import suwayomi.tachidesk.graphql.types.MetaInput
|
import suwayomi.tachidesk.graphql.types.MetaInput
|
||||||
import suwayomi.tachidesk.graphql.types.SyncConflictInfoType
|
import suwayomi.tachidesk.graphql.types.SyncConflictInfoType
|
||||||
import suwayomi.tachidesk.manga.impl.Chapter
|
import suwayomi.tachidesk.manga.impl.Chapter
|
||||||
|
import suwayomi.tachidesk.manga.impl.Manga
|
||||||
import suwayomi.tachidesk.manga.impl.chapter.getChapterDownloadReadyById
|
import suwayomi.tachidesk.manga.impl.chapter.getChapterDownloadReadyById
|
||||||
import suwayomi.tachidesk.manga.impl.sync.KoreaderSyncService
|
import suwayomi.tachidesk.manga.impl.sync.KoreaderSyncService
|
||||||
import suwayomi.tachidesk.manga.model.table.ChapterMetaTable
|
import suwayomi.tachidesk.manga.model.table.ChapterMetaTable
|
||||||
@@ -173,7 +174,7 @@ class ChapterMutation {
|
|||||||
val (clientMutationId, mangaId) = input
|
val (clientMutationId, mangaId) = input
|
||||||
|
|
||||||
return future {
|
return future {
|
||||||
Chapter.fetchChapterList(mangaId)
|
Manga.updateMangaAndChapters(mangaId, updateManga = false)
|
||||||
|
|
||||||
val chapters =
|
val chapters =
|
||||||
transaction {
|
transaction {
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ class MangaMutation {
|
|||||||
val (clientMutationId, id) = input
|
val (clientMutationId, id) = input
|
||||||
|
|
||||||
return future {
|
return future {
|
||||||
Manga.fetchManga(id)
|
Manga.updateMangaAndChapters(id, updateChapters = false)
|
||||||
|
|
||||||
val manga =
|
val manga =
|
||||||
transaction {
|
transaction {
|
||||||
@@ -187,20 +187,11 @@ class MangaMutation {
|
|||||||
val (clientMutationId, id, fetchManga, fetchChapters) = input
|
val (clientMutationId, id, fetchManga, fetchChapters) = input
|
||||||
|
|
||||||
return future {
|
return future {
|
||||||
var mangaEntry =
|
Manga.updateMangaAndChapters(
|
||||||
transaction { MangaTable.selectAll().where { MangaTable.id eq id }.first() }
|
mangaId = id,
|
||||||
val source = getCatalogueSourceOrStub(mangaEntry[MangaTable.sourceReference])
|
updateManga = fetchManga,
|
||||||
val sMangaUpdate =
|
updateChapters = fetchChapters
|
||||||
Manga.fetchMangaAndChapters(
|
)
|
||||||
mangaEntry = mangaEntry,
|
|
||||||
source = source,
|
|
||||||
fetchDetails = fetchManga,
|
|
||||||
fetchChapters = fetchChapters,
|
|
||||||
)
|
|
||||||
|
|
||||||
Manga.updateMangaDatabase(mangaEntry, source, sMangaUpdate.manga)
|
|
||||||
mangaEntry = transaction { MangaTable.selectAll().where { MangaTable.id eq id }.first() }
|
|
||||||
Chapter.updateChapterListDatabase(mangaEntry, sMangaUpdate.chapters, source)
|
|
||||||
|
|
||||||
val (manga, chapters) =
|
val (manga, chapters) =
|
||||||
transaction {
|
transaction {
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ object Manga {
|
|||||||
return if (!onlineFetch && mangaEntry[MangaTable.initialized]) {
|
return if (!onlineFetch && mangaEntry[MangaTable.initialized]) {
|
||||||
MangaTable.toDataClass(mangaEntry)
|
MangaTable.toDataClass(mangaEntry)
|
||||||
} else { // initialize manga
|
} else { // initialize manga
|
||||||
fetchManga(mangaId) ?: return MangaTable.toDataClass(mangaEntry)
|
updateMangaAndChapters(mangaId, updateChapters = false)
|
||||||
|
|
||||||
mangaEntry = transaction { MangaTable.selectAll().where { MangaTable.id eq mangaId }.first() }
|
mangaEntry = transaction { MangaTable.selectAll().where { MangaTable.id eq mangaId }.first() }
|
||||||
|
|
||||||
@@ -152,6 +152,36 @@ object Manga {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun updateMangaAndChapters(
|
||||||
|
mangaId: Int,
|
||||||
|
updateManga: Boolean = true,
|
||||||
|
updateChapters: Boolean = true,
|
||||||
|
) {
|
||||||
|
mangaInfoMutex.get(mangaId) { Mutex() }.withLock {
|
||||||
|
var mangaEntry =
|
||||||
|
transaction { MangaTable.selectAll().where { MangaTable.id eq mangaId }.first() }
|
||||||
|
val source = getCatalogueSourceOrNull(mangaEntry[MangaTable.sourceReference])
|
||||||
|
?: throw NullPointerException("Missing source ${mangaEntry[MangaTable.sourceReference]}")
|
||||||
|
val mangaUpdate =
|
||||||
|
fetchMangaAndChapters(
|
||||||
|
mangaEntry,
|
||||||
|
source,
|
||||||
|
fetchDetails = updateManga,
|
||||||
|
fetchChapters = updateChapters,
|
||||||
|
)
|
||||||
|
|
||||||
|
if (updateManga) {
|
||||||
|
updateMangaDatabase(mangaEntry, source, mangaUpdate.manga)
|
||||||
|
mangaEntry = transaction {
|
||||||
|
MangaTable.selectAll().where { MangaTable.id eq mangaId }.first()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (updateChapters) {
|
||||||
|
Chapter.updateChapterListDatabase(mangaEntry, mangaUpdate.chapters, source)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun updateMangaDatabase(
|
fun updateMangaDatabase(
|
||||||
mangaEntry: ResultRow,
|
mangaEntry: ResultRow,
|
||||||
source: CatalogueSource,
|
source: CatalogueSource,
|
||||||
|
|||||||
@@ -311,10 +311,10 @@ class Updater : IUpdater {
|
|||||||
tracker[job.manga.id] =
|
tracker[job.manga.id] =
|
||||||
try {
|
try {
|
||||||
logger.info { "Updating ${job.manga}" }
|
logger.info { "Updating ${job.manga}" }
|
||||||
if (serverConfig.updateMangas.value || !job.manga.initialized) {
|
Manga.updateMangaAndChapters(
|
||||||
Manga.getManga(job.manga.id, true)
|
job.manga.id,
|
||||||
}
|
updateManga = serverConfig.updateMangas.value || !job.manga.initialized
|
||||||
Chapter.getChapterList(job.manga.id, true)
|
)
|
||||||
job.copy(status = JobStatus.COMPLETE)
|
job.copy(status = JobStatus.COMPLETE)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.error(e) { "Error while updating ${job.manga}" }
|
logger.error(e) { "Error while updating ${job.manga}" }
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package suwayomi.tachidesk.opds.impl
|
|||||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||||
import org.jetbrains.exposed.v1.core.SortOrder
|
import org.jetbrains.exposed.v1.core.SortOrder
|
||||||
import suwayomi.tachidesk.i18n.MR
|
import suwayomi.tachidesk.i18n.MR
|
||||||
|
import suwayomi.tachidesk.manga.impl.Manga
|
||||||
import suwayomi.tachidesk.manga.impl.MangaList.proxyThumbnailUrl
|
import suwayomi.tachidesk.manga.impl.MangaList.proxyThumbnailUrl
|
||||||
import suwayomi.tachidesk.manga.model.table.ChapterTable
|
import suwayomi.tachidesk.manga.model.table.ChapterTable
|
||||||
import suwayomi.tachidesk.opds.constants.OpdsConstants
|
import suwayomi.tachidesk.opds.constants.OpdsConstants
|
||||||
@@ -647,8 +648,7 @@ object OpdsFeedBuilder {
|
|||||||
// If no chapters are found in the database, attempt to fetch them from the source.
|
// If no chapters are found in the database, attempt to fetch them from the source.
|
||||||
if (chapterEntries.isEmpty() && totalChapters == 0L) {
|
if (chapterEntries.isEmpty() && totalChapters == 0L) {
|
||||||
try {
|
try {
|
||||||
suwayomi.tachidesk.manga.impl.Chapter
|
Manga.updateMangaAndChapters(mangaId, updateManga = false)
|
||||||
.fetchChapterList(mangaId)
|
|
||||||
|
|
||||||
// Re-query after fetching.
|
// Re-query after fetching.
|
||||||
val (refetchedChapters, refetchedTotal) =
|
val (refetchedChapters, refetchedTotal) =
|
||||||
|
|||||||
Reference in New Issue
Block a user