aggregate data

This commit is contained in:
Mateusz Gruszczyński
2026-07-28 11:43:40 +02:00
parent 176e7e4554
commit 916807bb5c
4 changed files with 94 additions and 11 deletions
+28 -8
View File
@@ -135,6 +135,10 @@ pub struct NoteListItem {
url: String,
protected: bool,
created_by: Option<String>,
participant_count: i64,
file_count: i64,
file_size_bytes: i64,
revision_count: i64,
}
#[derive(Debug, Serialize)]
@@ -224,17 +228,29 @@ pub async fn open_workspace(
bearer_token(&headers),
)
.await?;
let stats = db::list_note_stats(&state.db, workspace.id)
.await?
.into_iter()
.map(|stats| (stats.note_id, stats))
.collect::<std::collections::HashMap<_, _>>();
let notes = db::list_notes(&state.db, workspace.id)
.await?
.into_iter()
.map(|note| NoteListItem {
url: format!("/w/{}/n/{}", workspace.slug, note.slug),
slug: note.slug,
title: note.title,
created_at: db::normalize_timestamp(&note.created_at),
updated_at: db::normalize_timestamp(&note.updated_at),
protected: note.protected,
created_by: note.created_by,
.map(|note| {
let stats = stats.get(&note.id);
NoteListItem {
url: format!("/w/{}/n/{}", workspace.slug, note.slug),
slug: note.slug,
title: note.title,
created_at: db::normalize_timestamp(&note.created_at),
updated_at: db::normalize_timestamp(&note.updated_at),
protected: note.protected,
created_by: note.created_by,
participant_count: stats.map_or(0, |value| value.participant_count),
file_count: stats.map_or(0, |value| value.file_count),
file_size_bytes: stats.map_or(0, |value| value.file_size_bytes),
revision_count: stats.map_or(0, |value| value.revision_count),
}
})
.collect();
@@ -307,6 +323,10 @@ pub async fn create_note(
updated_at: db::normalize_timestamp(&note.updated_at),
protected: note.protected,
created_by: note.created_by,
participant_count: 0,
file_count: 0,
file_size_bytes: 0,
revision_count: 0,
}),
))
}