From b17718df9b514269232abeea66f73c358173bfbd Mon Sep 17 00:00:00 2001 From: Froidefond Julien Date: Mon, 16 Mar 2026 21:11:58 +0100 Subject: [PATCH] fix(stats): count authors from both author and authors fields The total_authors stat now combines distinct values from the legacy author column and the new authors array column. Co-Authored-By: Claude Opus 4.6 --- apps/api/src/stats.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/api/src/stats.rs b/apps/api/src/stats.rs index 0bb7dad..5850e6d 100644 --- a/apps/api/src/stats.rs +++ b/apps/api/src/stats.rs @@ -91,7 +91,11 @@ pub async fn get_stats( COUNT(DISTINCT NULLIF(series, '')) AS total_series, COUNT(DISTINCT library_id) AS total_libraries, COALESCE(SUM(page_count), 0)::BIGINT AS total_pages, - COUNT(DISTINCT author) FILTER (WHERE author IS NOT NULL AND author != '') AS total_authors, + (SELECT COUNT(DISTINCT a) FROM ( + SELECT DISTINCT UNNEST(authors) AS a FROM books WHERE authors != '{}' + UNION + SELECT DISTINCT author FROM books WHERE author IS NOT NULL AND author != '' + ) sub) AS total_authors, COUNT(*) FILTER (WHERE COALESCE(brp.status, 'unread') = 'unread') AS unread, COUNT(*) FILTER (WHERE brp.status = 'reading') AS reading, COUNT(*) FILTER (WHERE brp.status = 'read') AS read