Include content size in response
This commit is contained in:
parent
08914a8f16
commit
ffeec19ca7
3 changed files with 44 additions and 6 deletions
|
|
@ -135,8 +135,7 @@ impl Database {
|
||||||
vault: &VaultId,
|
vault: &VaultId,
|
||||||
transaction: Option<&mut Transaction<'_>>,
|
transaction: Option<&mut Transaction<'_>>,
|
||||||
) -> Result<Vec<DocumentVersionWithoutContent>> {
|
) -> Result<Vec<DocumentVersionWithoutContent>> {
|
||||||
let query = sqlx::query_as!(
|
let query = sqlx::query!(
|
||||||
DocumentVersionWithoutContent,
|
|
||||||
r#"
|
r#"
|
||||||
select
|
select
|
||||||
vault_update_id,
|
vault_update_id,
|
||||||
|
|
@ -145,7 +144,8 @@ impl Database {
|
||||||
updated_date as "updated_date: chrono::DateTime<Utc>",
|
updated_date as "updated_date: chrono::DateTime<Utc>",
|
||||||
is_deleted,
|
is_deleted,
|
||||||
user_id,
|
user_id,
|
||||||
device_id
|
device_id,
|
||||||
|
length(content) as "content_size: u64"
|
||||||
from latest_document_versions
|
from latest_document_versions
|
||||||
order by vault_update_id
|
order by vault_update_id
|
||||||
"#,
|
"#,
|
||||||
|
|
@ -159,6 +159,22 @@ impl Database {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
.context("Cannot fetch latest documents")
|
.context("Cannot fetch latest documents")
|
||||||
|
.map(|rows| {
|
||||||
|
rows.into_iter()
|
||||||
|
.map(|row| DocumentVersionWithoutContent {
|
||||||
|
vault_update_id: row.vault_update_id,
|
||||||
|
document_id: row.document_id.into(),
|
||||||
|
relative_path: row.relative_path,
|
||||||
|
updated_date: row.updated_date,
|
||||||
|
is_deleted: row.is_deleted,
|
||||||
|
user_id: row.user_id,
|
||||||
|
device_id: row.device_id,
|
||||||
|
content_size: row
|
||||||
|
.content_size
|
||||||
|
.expect("Content size can't be null but sqlx can't infer it"),
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the latest state of all documents (including deleted) in the
|
/// Return the latest state of all documents (including deleted) in the
|
||||||
|
|
@ -169,8 +185,7 @@ impl Database {
|
||||||
vault_update_id: VaultUpdateId,
|
vault_update_id: VaultUpdateId,
|
||||||
transaction: Option<&mut Transaction<'_>>,
|
transaction: Option<&mut Transaction<'_>>,
|
||||||
) -> Result<Vec<DocumentVersionWithoutContent>> {
|
) -> Result<Vec<DocumentVersionWithoutContent>> {
|
||||||
let query = sqlx::query_as!(
|
let query = sqlx::query!(
|
||||||
DocumentVersionWithoutContent,
|
|
||||||
r#"
|
r#"
|
||||||
select
|
select
|
||||||
vault_update_id,
|
vault_update_id,
|
||||||
|
|
@ -179,7 +194,8 @@ impl Database {
|
||||||
updated_date as "updated_date: chrono::DateTime<Utc>",
|
updated_date as "updated_date: chrono::DateTime<Utc>",
|
||||||
is_deleted,
|
is_deleted,
|
||||||
user_id,
|
user_id,
|
||||||
device_id
|
device_id,
|
||||||
|
length(content) as "content_size: u64"
|
||||||
from latest_document_versions
|
from latest_document_versions
|
||||||
where vault_update_id > ?
|
where vault_update_id > ?
|
||||||
order by vault_update_id
|
order by vault_update_id
|
||||||
|
|
@ -197,6 +213,22 @@ impl Database {
|
||||||
.with_context(|| {
|
.with_context(|| {
|
||||||
format!("Cannot fetch latest documents since vault_update_id {vault_update_id}")
|
format!("Cannot fetch latest documents since vault_update_id {vault_update_id}")
|
||||||
})
|
})
|
||||||
|
.map(|rows| {
|
||||||
|
rows.into_iter()
|
||||||
|
.map(|row| DocumentVersionWithoutContent {
|
||||||
|
vault_update_id: row.vault_update_id,
|
||||||
|
document_id: row.document_id.into(),
|
||||||
|
relative_path: row.relative_path,
|
||||||
|
updated_date: row.updated_date,
|
||||||
|
is_deleted: row.is_deleted,
|
||||||
|
user_id: row.user_id,
|
||||||
|
device_id: row.device_id,
|
||||||
|
content_size: row
|
||||||
|
.content_size
|
||||||
|
.expect("Content size can't be null but sqlx can't infer it"),
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_max_update_id_in_vault(
|
pub async fn get_max_update_id_in_vault(
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ pub struct DocumentVersionWithoutContent {
|
||||||
pub is_deleted: bool,
|
pub is_deleted: bool,
|
||||||
pub user_id: UserId,
|
pub user_id: UserId,
|
||||||
pub device_id: DeviceId,
|
pub device_id: DeviceId,
|
||||||
|
pub content_size: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<StoredDocumentVersion> for DocumentVersionWithoutContent {
|
impl From<StoredDocumentVersion> for DocumentVersionWithoutContent {
|
||||||
|
|
@ -47,6 +48,7 @@ impl From<StoredDocumentVersion> for DocumentVersionWithoutContent {
|
||||||
is_deleted: value.is_deleted,
|
is_deleted: value.is_deleted,
|
||||||
user_id: value.user_id,
|
user_id: value.user_id,
|
||||||
device_id: value.device_id,
|
device_id: value.device_id,
|
||||||
|
content_size: value.content.len() as u64,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -516,6 +516,8 @@ export interface components {
|
||||||
/** @description Response to an update document request. */
|
/** @description Response to an update document request. */
|
||||||
DocumentUpdateResponse:
|
DocumentUpdateResponse:
|
||||||
| {
|
| {
|
||||||
|
/** Format: uint64 */
|
||||||
|
contentSize: number;
|
||||||
deviceId: string;
|
deviceId: string;
|
||||||
/** Format: uuid */
|
/** Format: uuid */
|
||||||
documentId: string;
|
documentId: string;
|
||||||
|
|
@ -558,6 +560,8 @@ export interface components {
|
||||||
vaultUpdateId: number;
|
vaultUpdateId: number;
|
||||||
};
|
};
|
||||||
DocumentVersionWithoutContent: {
|
DocumentVersionWithoutContent: {
|
||||||
|
/** Format: uint64 */
|
||||||
|
contentSize: number;
|
||||||
deviceId: string;
|
deviceId: string;
|
||||||
/** Format: uuid */
|
/** Format: uuid */
|
||||||
documentId: string;
|
documentId: string;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue