change in confirm mechanism

This commit is contained in:
Mateusz Gruszczyński
2026-07-28 11:52:29 +02:00
parent 916807bb5c
commit dacb754226
+7 -1
View File
@@ -181,6 +181,12 @@ pub async fn list_note_stats(
DatabaseKind::Postgres => "$1",
DatabaseKind::Sqlite | DatabaseKind::MySql => "?",
};
// PostgreSQL promotes SUM(BIGINT) to NUMERIC. sqlx::Any cannot decode the
// database-specific NUMERIC type, so normalize the aggregate to BIGINT.
let file_size_sum = match pool.kind() {
DatabaseKind::Postgres => "COALESCE(SUM(f.size_bytes), 0)::BIGINT",
DatabaseKind::Sqlite | DatabaseKind::MySql => "COALESCE(SUM(f.size_bytes), 0)",
};
let query = format!(
"SELECT n.id AS note_id, \
((SELECT COUNT(DISTINCT r.author) FROM note_revisions r \
@@ -189,7 +195,7 @@ pub async fn list_note_stats(
SELECT 1 FROM note_revisions r WHERE r.note_id = n.id AND r.author = n.created_by\
) THEN 1 ELSE 0 END) AS participant_count, \
(SELECT COUNT(*) FROM note_files f WHERE f.note_id = n.id) AS file_count, \
(SELECT COALESCE(SUM(f.size_bytes), 0) FROM note_files f WHERE f.note_id = n.id) AS file_size_bytes, \
(SELECT {file_size_sum} FROM note_files f WHERE f.note_id = n.id) AS file_size_bytes, \
(SELECT COUNT(*) FROM note_revisions r WHERE r.note_id = n.id) AS revision_count \
FROM notes n WHERE n.workspace_id = {placeholder}"
);