aggregate data
This commit is contained in:
+28
-8
@@ -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(¬e.created_at),
|
||||
updated_at: db::normalize_timestamp(¬e.updated_at),
|
||||
protected: note.protected,
|
||||
created_by: note.created_by,
|
||||
.map(|note| {
|
||||
let stats = stats.get(¬e.id);
|
||||
NoteListItem {
|
||||
url: format!("/w/{}/n/{}", workspace.slug, note.slug),
|
||||
slug: note.slug,
|
||||
title: note.title,
|
||||
created_at: db::normalize_timestamp(¬e.created_at),
|
||||
updated_at: db::normalize_timestamp(¬e.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(¬e.updated_at),
|
||||
protected: note.protected,
|
||||
created_by: note.created_by,
|
||||
participant_count: 0,
|
||||
file_count: 0,
|
||||
file_size_bytes: 0,
|
||||
revision_count: 0,
|
||||
}),
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user