Don't create new doc if one already exists with the same content

This commit is contained in:
Andras Schmelczer 2025-01-03 14:40:52 +00:00
parent 88f65a20f0
commit 2911b195f4
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C

View file

@ -7,6 +7,7 @@ use axum_extra::{
headers::{authorization::Bearer, Authorization},
TypedHeader,
};
use log::info;
use schemars::JsonSchema;
use serde::Deserialize;
use sync_lib::{base64_to_bytes, merge};
@ -68,6 +69,19 @@ pub async fn create_document(
.context("Failed to decode bytes as UTF-8")
.map_err(client_error)?;
if merged_content == existing_version.content {
info!(
"Content of the new version is the same as the existing version. Not creating a \
new version."
);
transaction
.rollback()
.await
.context("Failed to rollback unecceseary transaction")
.map_err(server_error)?;
return Ok(Json(existing_version.into()));
}
StoredDocumentVersion {
vault_id,
vault_update_id: last_update_id + 1,