From fbb383b1f12d3a9447dcc54872c555b78eff526c Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Sun, 17 May 2026 01:41:37 +0200 Subject: [PATCH] Fix mangas query with active sorting and postgresql db (#2042) fixes #2036 --- CHANGELOG.md | 1 + .../suwayomi/tachidesk/graphql/queries/MangaQuery.kt | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) 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)