Don't create new doc if one already exists with the same content
This commit is contained in:
parent
88f65a20f0
commit
2911b195f4
1 changed files with 14 additions and 0 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue