Faster existence validation
This commit is contained in:
parent
81b4a08a59
commit
51a9436fd7
2 changed files with 20 additions and 10 deletions
|
|
@ -8,6 +8,20 @@ use super::{
|
|||
use anyhow::{Context as _, Result, ensure};
|
||||
|
||||
impl Database {
|
||||
pub async fn get_missing_document(
|
||||
tx: &mut Transaction<'_>,
|
||||
ids: &[DocumentId],
|
||||
) -> Result<Option<String>> {
|
||||
Ok(sqlx::query_scalar(
|
||||
"SELECT value FROM json_each(?) AS requested
|
||||
WHERE NOT EXISTS (SELECT 1 FROM documents WHERE document_id = requested.value)
|
||||
LIMIT 1",
|
||||
)
|
||||
.bind(serde_json::to_string(ids)?)
|
||||
.fetch_optional(&mut **tx)
|
||||
.await?)
|
||||
}
|
||||
|
||||
pub async fn get_request_event(
|
||||
tx: &mut Transaction<'_>,
|
||||
request_id: uuid::Uuid,
|
||||
|
|
|
|||
|
|
@ -62,18 +62,14 @@ pub async fn put_file_manifest(
|
|||
return Ok(Json(FileManifestUpdateResponse::StaleBase(latest)));
|
||||
}
|
||||
|
||||
for id in push.entries.keys() {
|
||||
if state
|
||||
.database
|
||||
.get_latest_document_version(&vault_id, id, Some(&mut tx))
|
||||
if let Some(id) =
|
||||
Database::get_missing_document(&mut tx, &push.entries.keys().copied().collect::<Vec<_>>())
|
||||
.await
|
||||
.map_err(server_error)?
|
||||
.is_none()
|
||||
{
|
||||
return Err(client_error(anyhow!(
|
||||
"File manifest references missing content: {id}"
|
||||
)));
|
||||
}
|
||||
{
|
||||
return Err(client_error(anyhow!(
|
||||
"File manifest references missing content: {id}"
|
||||
)));
|
||||
}
|
||||
|
||||
let file_manifest = FileManifest {
|
||||
|
|
|
|||
Loading…
Reference in a new issue