diff --git a/CHANGELOG.md b/CHANGELOG.md index a0b3ca474..04a2c41f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - (**Extension**) Do not indicate an update is available when the extension is not installed - (**Chapter**) Fix losing chapter data on failed chapter list update - (**Chapter**) Fix database error when fetching chapter updates +- (**Manga/API**) Fix "mangas" graphql query with active sorting and using a postgresql database (QUERY "mangas") ## [v2.2.2100] + [WebUI: v20260508.01] - 2026-05-08 diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/MangaQuery.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/MangaQuery.kt index fdbd790bd..1ec5d37f1 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/MangaQuery.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/MangaQuery.kt @@ -247,11 +247,18 @@ class MangaQuery { MangaTable .leftJoin(CategoryMangaTable) .select(MangaTable.columns) - .withDistinctOn(MangaTable.id) + + val applySorting = order != null || orderBy != null || (last != null || before != null) + + if (applySorting) { + res.withDistinctOn(MangaTable.id to SortOrder.ASC) + } else { + res.withDistinctOn(MangaTable.id) + } res.applyOps(condition, filter) - if (order != null || orderBy != null || (last != null || before != null)) { + if (applySorting) { val baseSort = listOf(MangaOrder(MangaOrderBy.ID, SortOrder.ASC)) val deprecatedSort = listOfNotNull(orderBy?.let { MangaOrder(orderBy, orderByType) }) val actualSort = (order.orEmpty() + deprecatedSort + baseSort)