Add Source Meta (#875)

This commit is contained in:
Mitchell Syer
2024-02-17 11:24:01 -05:00
committed by GitHub
parent ea6edaecc4
commit af0dde5ae8
8 changed files with 181 additions and 0 deletions

View File

@@ -12,9 +12,11 @@ import suwayomi.tachidesk.graphql.types.CategoryMetaType
import suwayomi.tachidesk.graphql.types.ChapterMetaType
import suwayomi.tachidesk.graphql.types.GlobalMetaType
import suwayomi.tachidesk.graphql.types.MangaMetaType
import suwayomi.tachidesk.graphql.types.SourceMetaType
import suwayomi.tachidesk.manga.model.table.CategoryMetaTable
import suwayomi.tachidesk.manga.model.table.ChapterMetaTable
import suwayomi.tachidesk.manga.model.table.MangaMetaTable
import suwayomi.tachidesk.manga.model.table.SourceMetaTable
import suwayomi.tachidesk.server.JavalinSetup.future
class GlobalMetaDataLoader : KotlinDataLoader<String, GlobalMetaType?> {
@@ -88,3 +90,21 @@ class CategoryMetaDataLoader : KotlinDataLoader<Int, List<CategoryMetaType>> {
}
}
}
class SourceMetaDataLoader : KotlinDataLoader<Long, List<SourceMetaType>> {
override val dataLoaderName = "SourceMetaDataLoader"
override fun getDataLoader(): DataLoader<Long, List<SourceMetaType>> =
DataLoaderFactory.newDataLoader<Long, List<SourceMetaType>> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val metasByRefId =
SourceMetaTable.select { SourceMetaTable.ref inList ids }
.map { SourceMetaType(it) }
.groupBy { it.sourceId }
ids.map { metasByRefId[it].orEmpty() }
}
}
}
}