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};
|
use anyhow::{Context as _, Result, ensure};
|
||||||
|
|
||||||
impl Database {
|
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(
|
pub async fn get_request_event(
|
||||||
tx: &mut Transaction<'_>,
|
tx: &mut Transaction<'_>,
|
||||||
request_id: uuid::Uuid,
|
request_id: uuid::Uuid,
|
||||||
|
|
|
||||||
|
|
@ -62,19 +62,15 @@ pub async fn put_file_manifest(
|
||||||
return Ok(Json(FileManifestUpdateResponse::StaleBase(latest)));
|
return Ok(Json(FileManifestUpdateResponse::StaleBase(latest)));
|
||||||
}
|
}
|
||||||
|
|
||||||
for id in push.entries.keys() {
|
if let Some(id) =
|
||||||
if state
|
Database::get_missing_document(&mut tx, &push.entries.keys().copied().collect::<Vec<_>>())
|
||||||
.database
|
|
||||||
.get_latest_document_version(&vault_id, id, Some(&mut tx))
|
|
||||||
.await
|
.await
|
||||||
.map_err(server_error)?
|
.map_err(server_error)?
|
||||||
.is_none()
|
|
||||||
{
|
{
|
||||||
return Err(client_error(anyhow!(
|
return Err(client_error(anyhow!(
|
||||||
"File manifest references missing content: {id}"
|
"File manifest references missing content: {id}"
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let file_manifest = FileManifest {
|
let file_manifest = FileManifest {
|
||||||
file_manifest_id: Database::allocate_event(&mut tx, push.request_id, &fingerprint)
|
file_manifest_id: Database::allocate_event(&mut tx, push.request_id, &fingerprint)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue