mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-03 10:54:38 -05:00
* Update graphqlkotlin to v8 * Go back to JsonMapper * Add context to data loaders * Compile fixes --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Syer10 <syer10@users.noreply.github.com>
66 lines
2.6 KiB
Kotlin
66 lines
2.6 KiB
Kotlin
/*
|
|
* Copyright (C) Contributors to the Suwayomi project
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
package suwayomi.tachidesk.graphql.dataLoaders
|
|
|
|
import com.expediagroup.graphql.dataloader.KotlinDataLoader
|
|
import graphql.GraphQLContext
|
|
import org.dataloader.DataLoader
|
|
import org.dataloader.DataLoaderFactory
|
|
import org.jetbrains.exposed.sql.Slf4jSqlDebugLogger
|
|
import org.jetbrains.exposed.sql.addLogger
|
|
import org.jetbrains.exposed.sql.select
|
|
import org.jetbrains.exposed.sql.transactions.transaction
|
|
import suwayomi.tachidesk.graphql.types.SourceNodeList
|
|
import suwayomi.tachidesk.graphql.types.SourceNodeList.Companion.toNodeList
|
|
import suwayomi.tachidesk.graphql.types.SourceType
|
|
import suwayomi.tachidesk.manga.model.table.ExtensionTable
|
|
import suwayomi.tachidesk.manga.model.table.SourceTable
|
|
import suwayomi.tachidesk.server.JavalinSetup.future
|
|
|
|
class SourceDataLoader : KotlinDataLoader<Long, SourceType?> {
|
|
override val dataLoaderName = "SourceDataLoader"
|
|
|
|
override fun getDataLoader(graphQLContext: GraphQLContext): DataLoader<Long, SourceType?> =
|
|
DataLoaderFactory.newDataLoader { ids ->
|
|
future {
|
|
transaction {
|
|
addLogger(Slf4jSqlDebugLogger)
|
|
val source =
|
|
SourceTable
|
|
.select { SourceTable.id inList ids }
|
|
.mapNotNull { SourceType(it) }
|
|
.associateBy { it.id }
|
|
ids.map { source[it] }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
class SourcesForExtensionDataLoader : KotlinDataLoader<String, SourceNodeList> {
|
|
override val dataLoaderName = "SourcesForExtensionDataLoader"
|
|
|
|
override fun getDataLoader(graphQLContext: GraphQLContext): DataLoader<String, SourceNodeList> =
|
|
DataLoaderFactory.newDataLoader { ids ->
|
|
future {
|
|
transaction {
|
|
addLogger(Slf4jSqlDebugLogger)
|
|
|
|
val sourcesByExtensionPkg =
|
|
SourceTable
|
|
.innerJoin(ExtensionTable)
|
|
.select { ExtensionTable.pkgName inList ids }
|
|
.map { Pair(it[ExtensionTable.pkgName], SourceType(it)) }
|
|
.groupBy { it.first }
|
|
.mapValues { it.value.mapNotNull { pair -> pair.second } }
|
|
|
|
ids.map { (sourcesByExtensionPkg[it] ?: emptyList()).toNodeList() }
|
|
}
|
|
}
|
|
}
|
|
}
|