Initialize manga on add to library (#1016)
In case a manga gets added to the library which has not been initialized yet, it should be tried to initialize it. Since it's not an error to have uninitialized manga in the library, this can be done in the background via the updater and the client receives the updated data via the update subscription.
This commit is contained in:
@@ -7,13 +7,18 @@ import org.jetbrains.exposed.sql.deleteWhere
|
||||
import org.jetbrains.exposed.sql.select
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import org.jetbrains.exposed.sql.update
|
||||
import org.kodein.di.DI
|
||||
import org.kodein.di.conf.global
|
||||
import org.kodein.di.instance
|
||||
import suwayomi.tachidesk.graphql.asDataFetcherResult
|
||||
import suwayomi.tachidesk.graphql.types.MangaMetaType
|
||||
import suwayomi.tachidesk.graphql.types.MangaType
|
||||
import suwayomi.tachidesk.manga.impl.Library
|
||||
import suwayomi.tachidesk.manga.impl.Manga
|
||||
import suwayomi.tachidesk.manga.impl.update.IUpdater
|
||||
import suwayomi.tachidesk.manga.model.table.MangaMetaTable
|
||||
import suwayomi.tachidesk.manga.model.table.MangaTable
|
||||
import suwayomi.tachidesk.manga.model.table.toDataClass
|
||||
import suwayomi.tachidesk.server.JavalinSetup.future
|
||||
import java.time.Instant
|
||||
import java.util.concurrent.CompletableFuture
|
||||
@@ -24,6 +29,8 @@ import java.util.concurrent.CompletableFuture
|
||||
* - Delete read/all downloaded chapters
|
||||
*/
|
||||
class MangaMutation {
|
||||
private val updater by DI.global.instance<IUpdater>()
|
||||
|
||||
data class UpdateMangaPatch(
|
||||
val inLibrary: Boolean? = null,
|
||||
)
|
||||
@@ -65,6 +72,17 @@ class MangaMutation {
|
||||
}
|
||||
}.apply {
|
||||
if (patch.inLibrary != null) {
|
||||
transaction {
|
||||
// try to initialize uninitialized in library manga to ensure that the expected data is available (chapter list, metadata, ...)
|
||||
val mangas =
|
||||
transaction {
|
||||
MangaTable.select { (MangaTable.id inList ids) and (MangaTable.initialized eq false) }
|
||||
.map { MangaTable.toDataClass(it) }
|
||||
}
|
||||
|
||||
updater.addMangasToQueue(mangas)
|
||||
}
|
||||
|
||||
ids.forEach {
|
||||
Library.handleMangaThumbnail(it, patch.inLibrary)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package suwayomi.tachidesk.manga.impl.update
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import suwayomi.tachidesk.manga.model.dataclass.CategoryDataClass
|
||||
import suwayomi.tachidesk.manga.model.dataclass.MangaDataClass
|
||||
|
||||
interface IUpdater {
|
||||
fun getLastUpdateTimestamp(): Long
|
||||
@@ -13,6 +14,8 @@ interface IUpdater {
|
||||
forceAll: Boolean,
|
||||
)
|
||||
|
||||
fun addMangasToQueue(mangas: List<MangaDataClass>)
|
||||
|
||||
val status: Flow<UpdateStatus>
|
||||
|
||||
val statusDeprecated: StateFlow<UpdateStatus>
|
||||
|
||||
@@ -329,11 +329,11 @@ class Updater : IUpdater {
|
||||
)
|
||||
}
|
||||
|
||||
private fun addMangasToQueue(mangasToUpdate: List<MangaDataClass>) {
|
||||
override fun addMangasToQueue(mangas: List<MangaDataClass>) {
|
||||
// create all manga update jobs before adding them to the queue so that the client is able to calculate the
|
||||
// progress properly right form the start
|
||||
mangasToUpdate.forEach { tracker[it.id] = UpdateJob(it) }
|
||||
mangasToUpdate.forEach { addMangaToQueue(it) }
|
||||
mangas.forEach { tracker[it.id] = UpdateJob(it) }
|
||||
mangas.forEach { addMangaToQueue(it) }
|
||||
}
|
||||
|
||||
private fun addMangaToQueue(manga: MangaDataClass) {
|
||||
|
||||
Reference in New Issue
Block a user