mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-04 03:14:40 -05:00
Add highest numbered chapter function in MangaType (#1397)
* Add highest numbered chapter function in MangaType * Fix name
This commit is contained in:
@@ -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) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user