From 89b84252a5b998ff9908e9907db6e3d242198d4f Mon Sep 17 00:00:00 2001 From: MechaCat02 Date: Sun, 24 May 2026 22:20:15 +0200 Subject: [PATCH] bugfix: subquery-wrap pending chapters query so DISTINCT + ORDER BY agree (0.26.1) PG rejects `SELECT DISTINCT c.id, c.manga_id, cs.source_url ... ORDER BY c.manga_id, c.created_at` because the ORDER BY references a column not in the DISTINCT projection. Wrap the DISTINCT in a subquery (which includes created_at) and apply the ORDER BY in the outer SELECT. Co-Authored-By: Claude Opus 4.7 (1M context) --- backend/Cargo.lock | 2 +- backend/Cargo.toml | 2 +- backend/src/bin/crawler.rs | 25 +++++++++++++++++-------- frontend/package.json | 2 +- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 5979f8d..db763fc 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -1448,7 +1448,7 @@ checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" [[package]] name = "mangalord" -version = "0.26.0" +version = "0.26.1" dependencies = [ "anyhow", "argon2", diff --git a/backend/Cargo.toml b/backend/Cargo.toml index de08c88..418ddb1 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mangalord" -version = "0.26.0" +version = "0.26.1" edition = "2021" default-run = "mangalord" diff --git a/backend/src/bin/crawler.rs b/backend/src/bin/crawler.rs index 88f95d8..9021a4a 100644 --- a/backend/src/bin/crawler.rs +++ b/backend/src/bin/crawler.rs @@ -424,16 +424,25 @@ async fn sync_bookmarked_chapter_content( workers: usize, force_refetch: bool, ) -> anyhow::Result<()> { + // Subquery first so DISTINCT collapses multi-user bookmark rows + // without forcing every ORDER BY column into the SELECT list (PG + // rejects `ORDER BY c.created_at` against `SELECT DISTINCT c.id, + // c.manga_id, cs.source_url` with "ORDER BY expressions must + // appear in select list"). Outer ORDER BY then groups chapters by + // their manga, oldest first, so backfills proceed in reading + // order per manga. let pending: Vec<(Uuid, Uuid, String)> = sqlx::query_as( r#" - SELECT DISTINCT c.id, c.manga_id, cs.source_url - FROM chapters c - JOIN bookmarks b ON b.manga_id = c.manga_id - JOIN chapter_sources cs ON cs.chapter_id = c.id - WHERE cs.source_id = $1 - AND cs.dropped_at IS NULL - AND (c.page_count = 0 OR $2) - ORDER BY c.manga_id, c.created_at ASC + SELECT id, manga_id, source_url FROM ( + SELECT DISTINCT c.id, c.manga_id, c.created_at, cs.source_url + FROM chapters c + JOIN bookmarks b ON b.manga_id = c.manga_id + JOIN chapter_sources cs ON cs.chapter_id = c.id + WHERE cs.source_id = $1 + AND cs.dropped_at IS NULL + AND (c.page_count = 0 OR $2) + ) sub + ORDER BY manga_id, created_at ASC "#, ) .bind(source_id) diff --git a/frontend/package.json b/frontend/package.json index ee2158a..c995e89 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "mangalord-frontend", - "version": "0.26.0", + "version": "0.26.1", "private": true, "type": "module", "scripts": {