Minor cleanup
This commit is contained in:
@@ -17,12 +17,12 @@ import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import suwayomi.tachidesk.graphql.types.CategoryType
|
||||
import suwayomi.tachidesk.manga.model.table.CategoryMangaTable
|
||||
import suwayomi.tachidesk.manga.model.table.CategoryTable
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import suwayomi.tachidesk.server.JavalinSetup.future
|
||||
|
||||
class CategoryDataLoader : KotlinDataLoader<Int, CategoryType> {
|
||||
override val dataLoaderName = "CategoryDataLoader"
|
||||
override fun getDataLoader(): DataLoader<Int, CategoryType> = DataLoaderFactory.newDataLoader<Int, CategoryType> { ids ->
|
||||
CompletableFuture.supplyAsync {
|
||||
future {
|
||||
transaction {
|
||||
addLogger(StdOutSqlLogger)
|
||||
CategoryTable.select { CategoryTable.id inList ids }
|
||||
@@ -35,10 +35,11 @@ class CategoryDataLoader : KotlinDataLoader<Int, CategoryType> {
|
||||
class CategoriesForMangaDataLoader : KotlinDataLoader<Int, List<CategoryType>> {
|
||||
override val dataLoaderName = "CategoriesForMangaDataLoader"
|
||||
override fun getDataLoader(): DataLoader<Int, List<CategoryType>> = DataLoaderFactory.newDataLoader<Int, List<CategoryType>> { ids ->
|
||||
CompletableFuture.supplyAsync {
|
||||
future {
|
||||
transaction {
|
||||
addLogger(StdOutSqlLogger)
|
||||
val itemsByRef = CategoryMangaTable.innerJoin(CategoryTable).select { CategoryMangaTable.manga inList ids }
|
||||
val itemsByRef = CategoryMangaTable.innerJoin(CategoryTable)
|
||||
.select { CategoryMangaTable.manga inList ids }
|
||||
.map { Pair(it[CategoryMangaTable.manga].value, CategoryType(it)) }
|
||||
.groupBy { it.first }
|
||||
.mapValues { it.value.map { pair -> pair.second } }
|
||||
|
||||
@@ -16,12 +16,12 @@ import org.jetbrains.exposed.sql.select
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import suwayomi.tachidesk.graphql.types.ChapterType
|
||||
import suwayomi.tachidesk.manga.model.table.ChapterTable
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import suwayomi.tachidesk.server.JavalinSetup.future
|
||||
|
||||
class ChapterDataLoader : KotlinDataLoader<Int, ChapterType> {
|
||||
override val dataLoaderName = "ChapterDataLoader"
|
||||
override fun getDataLoader(): DataLoader<Int, ChapterType> = DataLoaderFactory.newDataLoader<Int, ChapterType> { ids ->
|
||||
CompletableFuture.supplyAsync {
|
||||
future {
|
||||
transaction {
|
||||
addLogger(StdOutSqlLogger)
|
||||
ChapterTable.select { ChapterTable.id inList ids }
|
||||
@@ -34,7 +34,7 @@ class ChapterDataLoader : KotlinDataLoader<Int, ChapterType> {
|
||||
class ChaptersForMangaDataLoader : KotlinDataLoader<Int, List<ChapterType>> {
|
||||
override val dataLoaderName = "ChaptersForMangaDataLoader"
|
||||
override fun getDataLoader(): DataLoader<Int, List<ChapterType>> = DataLoaderFactory.newDataLoader<Int, List<ChapterType>> { ids ->
|
||||
CompletableFuture.supplyAsync {
|
||||
future {
|
||||
transaction {
|
||||
addLogger(StdOutSqlLogger)
|
||||
val chaptersByMangaId = ChapterTable.select { ChapterTable.manga inList ids }
|
||||
|
||||
@@ -18,12 +18,12 @@ import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import suwayomi.tachidesk.graphql.types.MangaType
|
||||
import suwayomi.tachidesk.manga.model.table.CategoryMangaTable
|
||||
import suwayomi.tachidesk.manga.model.table.MangaTable
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import suwayomi.tachidesk.server.JavalinSetup.future
|
||||
|
||||
class MangaDataLoader : KotlinDataLoader<Int, MangaType> {
|
||||
override val dataLoaderName = "MangaDataLoader"
|
||||
override fun getDataLoader(): DataLoader<Int, MangaType> = DataLoaderFactory.newDataLoader<Int, MangaType> { ids ->
|
||||
CompletableFuture.supplyAsync {
|
||||
future {
|
||||
transaction {
|
||||
addLogger(StdOutSqlLogger)
|
||||
MangaTable.select { MangaTable.id inList ids }
|
||||
@@ -36,7 +36,7 @@ class MangaDataLoader : KotlinDataLoader<Int, MangaType> {
|
||||
class MangaForCategoryDataLoader : KotlinDataLoader<Int, List<MangaType>> {
|
||||
override val dataLoaderName = "MangaForCategoryDataLoader"
|
||||
override fun getDataLoader(): DataLoader<Int, List<MangaType>> = DataLoaderFactory.newDataLoader<Int, List<MangaType>> { ids ->
|
||||
CompletableFuture.supplyAsync {
|
||||
future {
|
||||
transaction {
|
||||
addLogger(StdOutSqlLogger)
|
||||
val itemsByRef = CategoryMangaTable.innerJoin(MangaTable).select { CategoryMangaTable.category inList ids }
|
||||
|
||||
@@ -13,12 +13,12 @@ import suwayomi.tachidesk.graphql.types.MangaMetaItem
|
||||
import suwayomi.tachidesk.graphql.types.MetaType
|
||||
import suwayomi.tachidesk.manga.model.table.ChapterMetaTable
|
||||
import suwayomi.tachidesk.manga.model.table.MangaMetaTable
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import suwayomi.tachidesk.server.JavalinSetup.future
|
||||
|
||||
class ChapterMetaDataLoader : KotlinDataLoader<Int, MetaType> {
|
||||
override val dataLoaderName = "ChapterMetaDataLoader"
|
||||
override fun getDataLoader(): DataLoader<Int, MetaType> = DataLoaderFactory.newDataLoader<Int, MetaType> { ids ->
|
||||
CompletableFuture.supplyAsync {
|
||||
future {
|
||||
transaction {
|
||||
addLogger(StdOutSqlLogger)
|
||||
val metasByRefId = ChapterMetaTable.select { ChapterMetaTable.ref inList ids }
|
||||
@@ -33,7 +33,7 @@ class ChapterMetaDataLoader : KotlinDataLoader<Int, MetaType> {
|
||||
class MangaMetaDataLoader : KotlinDataLoader<Int, MetaType> {
|
||||
override val dataLoaderName = "MangaMetaDataLoader"
|
||||
override fun getDataLoader(): DataLoader<Int, MetaType> = DataLoaderFactory.newDataLoader<Int, MetaType> { ids ->
|
||||
CompletableFuture.supplyAsync {
|
||||
future {
|
||||
transaction {
|
||||
addLogger(StdOutSqlLogger)
|
||||
val metasByRefId = MangaMetaTable.select { MangaMetaTable.ref inList ids }
|
||||
@@ -48,7 +48,7 @@ class MangaMetaDataLoader : KotlinDataLoader<Int, MetaType> {
|
||||
class CategoryMetaDataLoader : KotlinDataLoader<Int, MetaType> {
|
||||
override val dataLoaderName = "CategoryMetaDataLoader"
|
||||
override fun getDataLoader(): DataLoader<Int, MetaType> = DataLoaderFactory.newDataLoader<Int, MetaType> { ids ->
|
||||
CompletableFuture.supplyAsync {
|
||||
future {
|
||||
transaction {
|
||||
addLogger(StdOutSqlLogger)
|
||||
val metasByRefId = MangaMetaTable.select { MangaMetaTable.ref inList ids }
|
||||
|
||||
+3
-5
@@ -26,7 +26,7 @@ import kotlinx.coroutines.flow.onStart
|
||||
import kotlinx.coroutines.flow.sample
|
||||
import kotlinx.coroutines.job
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.slf4j.LoggerFactory
|
||||
import mu.KotlinLogging
|
||||
import suwayomi.tachidesk.graphql.server.TachideskGraphQLContextFactory
|
||||
import suwayomi.tachidesk.graphql.server.subscriptions.SubscriptionOperationMessage.ClientMessages.*
|
||||
import suwayomi.tachidesk.graphql.server.subscriptions.SubscriptionOperationMessage.ServerMessages.*
|
||||
@@ -43,15 +43,14 @@ class ApolloSubscriptionProtocolHandler(
|
||||
private val objectMapper: ObjectMapper
|
||||
) {
|
||||
private val sessionState = ApolloSubscriptionSessionState()
|
||||
private val logger = LoggerFactory.getLogger(ApolloSubscriptionProtocolHandler::class.java)
|
||||
private val logger = KotlinLogging.logger {}
|
||||
private val keepAliveMessage = SubscriptionOperationMessage(type = GQL_CONNECTION_KEEP_ALIVE.type)
|
||||
private val basicConnectionErrorMessage = SubscriptionOperationMessage(type = GQL_CONNECTION_ERROR.type)
|
||||
private val acknowledgeMessage = SubscriptionOperationMessage(GQL_CONNECTION_ACK.type)
|
||||
|
||||
@Suppress("Detekt.TooGenericExceptionCaught")
|
||||
fun handleMessage(context: WsMessageContext): Flow<SubscriptionOperationMessage> {
|
||||
val operationMessage = convertToMessageOrNull(context.message()) ?: return flowOf(basicConnectionErrorMessage)
|
||||
logger.debug("GraphQL subscription client message, sessionId=${context.sessionId} operationMessage=$operationMessage")
|
||||
logger.debug { "GraphQL subscription client message, sessionId=${context.sessionId} operationMessage=$operationMessage" }
|
||||
|
||||
return try {
|
||||
when (operationMessage.type) {
|
||||
@@ -70,7 +69,6 @@ class ApolloSubscriptionProtocolHandler(
|
||||
onDisconnect(context)
|
||||
}
|
||||
|
||||
@Suppress("Detekt.TooGenericExceptionCaught")
|
||||
private fun convertToMessageOrNull(payload: String): SubscriptionOperationMessage? {
|
||||
return try {
|
||||
objectMapper.readValue(payload)
|
||||
|
||||
Reference in New Issue
Block a user