From 5eab462287e7ff2884859be853ffba60ab3618c5 Mon Sep 17 00:00:00 2001 From: Trezy Date: Tue, 24 Feb 2026 15:28:20 -0600 Subject: [PATCH] fix: show collections on Records page even if they have no records --- src/admin/stats.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/admin/stats.rs b/src/admin/stats.rs index 88bdc76..7320483 100644 --- a/src/admin/stats.rs +++ b/src/admin/stats.rs @@ -18,7 +18,17 @@ pub(super) async fn stats( .map_err(|e| AppError::Internal(format!("failed to count records: {e}")))?; let collections: Vec<(String, i64)> = sqlx::query_as( - "SELECT collection, COUNT(*) FROM records GROUP BY collection ORDER BY collection", + r#" + SELECT c.collection, COALESCE(r.cnt, 0) AS count + FROM ( + SELECT id AS collection FROM lexicons + WHERE lexicon_json->'defs'->'main'->>'type' = 'record' + ) c + LEFT JOIN ( + SELECT collection, COUNT(*) AS cnt FROM records GROUP BY collection + ) r ON r.collection = c.collection + ORDER BY c.collection + "#, ) .fetch_all(&state.db) .await -- 2.54.0