mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-04 19:34:35 -05:00
Feature/updater provide more info about update (#657)
* Provide last global update timestamp * Provide skipped mangas in update status * Extract update status logic into function * Rename update "statusMap" to "mangaStatusMap" * Provide info about categories in update status
This commit is contained in:
@@ -36,6 +36,22 @@ class CategoryDataLoader : KotlinDataLoader<Int, CategoryType> {
|
||||
}
|
||||
}
|
||||
|
||||
class CategoryForIdsDataLoader : KotlinDataLoader<List<Int>, CategoryNodeList> {
|
||||
override val dataLoaderName = "CategoryForIdsDataLoader"
|
||||
override fun getDataLoader(): DataLoader<List<Int>, CategoryNodeList> = DataLoaderFactory.newDataLoader { categoryIds ->
|
||||
future {
|
||||
transaction {
|
||||
addLogger(Slf4jSqlDebugLogger)
|
||||
val ids = categoryIds.flatten().distinct()
|
||||
val categories = CategoryTable.select { CategoryTable.id inList ids }.map { CategoryType(it) }
|
||||
categoryIds.map { categoryIds ->
|
||||
categories.filter { it.id in categoryIds }.toNodeList()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CategoriesForMangaDataLoader : KotlinDataLoader<Int, CategoryNodeList> {
|
||||
override val dataLoaderName = "CategoriesForMangaDataLoader"
|
||||
override fun getDataLoader(): DataLoader<Int, CategoryNodeList> = DataLoaderFactory.newDataLoader<Int, CategoryNodeList> { ids ->
|
||||
|
||||
@@ -4,21 +4,18 @@ import org.kodein.di.DI
|
||||
import org.kodein.di.conf.global
|
||||
import org.kodein.di.instance
|
||||
import suwayomi.tachidesk.graphql.types.UpdateStatus
|
||||
import suwayomi.tachidesk.graphql.types.UpdateStatusType
|
||||
import suwayomi.tachidesk.manga.impl.update.IUpdater
|
||||
import suwayomi.tachidesk.manga.impl.update.JobStatus
|
||||
|
||||
class UpdateQuery {
|
||||
private val updater by DI.global.instance<IUpdater>()
|
||||
|
||||
fun updateStatus(): UpdateStatus {
|
||||
val status = updater.status.value
|
||||
return UpdateStatus(
|
||||
isRunning = status.running,
|
||||
pendingJobs = UpdateStatusType(status.statusMap[JobStatus.PENDING]?.map { it.id }.orEmpty()),
|
||||
runningJobs = UpdateStatusType(status.statusMap[JobStatus.RUNNING]?.map { it.id }.orEmpty()),
|
||||
completeJobs = UpdateStatusType(status.statusMap[JobStatus.COMPLETE]?.map { it.id }.orEmpty()),
|
||||
failedJobs = UpdateStatusType(status.statusMap[JobStatus.FAILED]?.map { it.id }.orEmpty())
|
||||
)
|
||||
return UpdateStatus(updater.status.value)
|
||||
}
|
||||
|
||||
data class LastUpdateTimestampPayload(val timestamp: Long)
|
||||
|
||||
fun lastUpdateTimestamp(): LastUpdateTimestampPayload {
|
||||
return LastUpdateTimestampPayload(updater.getLastUpdateTimestamp())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ package suwayomi.tachidesk.graphql.server
|
||||
import com.expediagroup.graphql.dataloader.KotlinDataLoaderRegistryFactory
|
||||
import suwayomi.tachidesk.graphql.dataLoaders.CategoriesForMangaDataLoader
|
||||
import suwayomi.tachidesk.graphql.dataLoaders.CategoryDataLoader
|
||||
import suwayomi.tachidesk.graphql.dataLoaders.CategoryForIdsDataLoader
|
||||
import suwayomi.tachidesk.graphql.dataLoaders.CategoryMetaDataLoader
|
||||
import suwayomi.tachidesk.graphql.dataLoaders.ChapterDataLoader
|
||||
import suwayomi.tachidesk.graphql.dataLoaders.ChapterMetaDataLoader
|
||||
@@ -39,6 +40,7 @@ class TachideskDataLoaderRegistryFactory {
|
||||
MangaForSourceDataLoader(),
|
||||
MangaForIdsDataLoader(),
|
||||
CategoryDataLoader(),
|
||||
CategoryForIdsDataLoader(),
|
||||
CategoryMetaDataLoader(),
|
||||
CategoriesForMangaDataLoader(),
|
||||
SourceDataLoader(),
|
||||
|
||||
@@ -3,26 +3,42 @@ package suwayomi.tachidesk.graphql.types
|
||||
import com.expediagroup.graphql.generator.annotations.GraphQLIgnore
|
||||
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
|
||||
import graphql.schema.DataFetchingEnvironment
|
||||
import suwayomi.tachidesk.manga.impl.update.CategoryUpdateStatus
|
||||
import suwayomi.tachidesk.manga.impl.update.JobStatus
|
||||
import suwayomi.tachidesk.manga.impl.update.UpdateStatus
|
||||
import java.util.concurrent.CompletableFuture
|
||||
|
||||
class UpdateStatus(
|
||||
val isRunning: Boolean,
|
||||
val skippedCategories: UpdateStatusCategoryType,
|
||||
val updatingCategories: UpdateStatusCategoryType,
|
||||
val pendingJobs: UpdateStatusType,
|
||||
val runningJobs: UpdateStatusType,
|
||||
val completeJobs: UpdateStatusType,
|
||||
val failedJobs: UpdateStatusType
|
||||
val failedJobs: UpdateStatusType,
|
||||
val skippedJobs: UpdateStatusType
|
||||
) {
|
||||
constructor(status: UpdateStatus) : this(
|
||||
isRunning = status.running,
|
||||
pendingJobs = UpdateStatusType(status.statusMap[JobStatus.PENDING]?.map { it.id }.orEmpty()),
|
||||
runningJobs = UpdateStatusType(status.statusMap[JobStatus.RUNNING]?.map { it.id }.orEmpty()),
|
||||
completeJobs = UpdateStatusType(status.statusMap[JobStatus.COMPLETE]?.map { it.id }.orEmpty()),
|
||||
failedJobs = UpdateStatusType(status.statusMap[JobStatus.FAILED]?.map { it.id }.orEmpty())
|
||||
skippedCategories = UpdateStatusCategoryType(status.categoryStatusMap[CategoryUpdateStatus.SKIPPED]?.map { it.id }.orEmpty()),
|
||||
updatingCategories = UpdateStatusCategoryType(status.categoryStatusMap[CategoryUpdateStatus.UPDATING]?.map { it.id }.orEmpty()),
|
||||
pendingJobs = UpdateStatusType(status.mangaStatusMap[JobStatus.PENDING]?.map { it.id }.orEmpty()),
|
||||
runningJobs = UpdateStatusType(status.mangaStatusMap[JobStatus.RUNNING]?.map { it.id }.orEmpty()),
|
||||
completeJobs = UpdateStatusType(status.mangaStatusMap[JobStatus.COMPLETE]?.map { it.id }.orEmpty()),
|
||||
failedJobs = UpdateStatusType(status.mangaStatusMap[JobStatus.FAILED]?.map { it.id }.orEmpty()),
|
||||
skippedJobs = UpdateStatusType(status.mangaStatusMap[JobStatus.SKIPPED]?.map { it.id }.orEmpty())
|
||||
)
|
||||
}
|
||||
|
||||
class UpdateStatusCategoryType(
|
||||
@get:GraphQLIgnore
|
||||
val categoryIds: List<Int>
|
||||
) {
|
||||
fun categories(dataFetchingEnvironment: DataFetchingEnvironment): CompletableFuture<CategoryNodeList> {
|
||||
return dataFetchingEnvironment.getValueFromDataLoader("CategoryForIdsDataLoader", categoryIds)
|
||||
}
|
||||
}
|
||||
|
||||
class UpdateStatusType(
|
||||
@get:GraphQLIgnore
|
||||
val mangaIds: List<Int>
|
||||
|
||||
Reference in New Issue
Block a user