Add highest numbered chapter function in MangaType (#1397)

* Add highest numbered chapter function in MangaType

* Fix name
This commit is contained in:
Mitchell Syer
2025-05-22 19:58:09 -04:00
committed by GitHub
parent 0405a535c7
commit ec870759cf
5 changed files with 31 additions and 2 deletions

View File

@@ -256,3 +256,27 @@ class FirstUnreadChapterForMangaDataLoader : KotlinDataLoader<Int, ChapterType?>
}
}
}
class HighestNumberedChapterForMangaDataLoader : KotlinDataLoader<Int, ChapterType?> {
override val dataLoaderName = "HighestNumberedChapterForMangaDataLoader"
override fun getDataLoader(graphQLContext: GraphQLContext): DataLoader<Int, ChapterType?> =
DataLoaderFactory.newDataLoader<Int, ChapterType?> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val highestNumberedChaptersByMangaId =
ChapterTable
.selectAll()
.where { (ChapterTable.manga inList ids) and (ChapterTable.chapter_number greater 0f) }
.orderBy(ChapterTable.chapter_number to SortOrder.DESC_NULLS_LAST)
.groupBy { it[ChapterTable.manga].value }
ids.map { id ->
highestNumberedChaptersByMangaId[id]
?.firstOrNull()
?.let { chapter -> ChapterType(chapter) }
}
}
}
}
}