no remote path chacnge
This commit is contained in:
parent
19d5dc1999
commit
17a1f4d060
16 changed files with 93 additions and 314 deletions
|
|
@ -11,10 +11,7 @@ use super::{device_id_header::DeviceIdHeader, requests::CreateDocumentVersion};
|
|||
use crate::{
|
||||
app_state::{
|
||||
AppState,
|
||||
database::{
|
||||
InsertBroadcast,
|
||||
models::{StoredDocumentVersion, VaultId},
|
||||
},
|
||||
database::models::{StoredDocumentVersion, VaultId},
|
||||
},
|
||||
config::user_config::User,
|
||||
errors::{SyncServerError, client_error, server_error, write_transaction_error},
|
||||
|
|
@ -128,8 +125,6 @@ pub async fn create_document(
|
|||
);
|
||||
}
|
||||
|
||||
let path_changed = deduped_path != sanitized_relative_path;
|
||||
|
||||
let new_vault_update_id = last_update_id + 1;
|
||||
let new_version = StoredDocumentVersion {
|
||||
vault_update_id: new_vault_update_id,
|
||||
|
|
@ -146,17 +141,7 @@ pub async fn create_document(
|
|||
|
||||
state
|
||||
.database
|
||||
.insert_document_version(
|
||||
&vault_id,
|
||||
&new_version,
|
||||
transaction,
|
||||
InsertBroadcast {
|
||||
// A brand-new document is always a content change for peers.
|
||||
content_changed: true,
|
||||
// Origin needs to know if the server deduped its requested path.
|
||||
path_changed,
|
||||
},
|
||||
)
|
||||
.insert_document_version(&vault_id, &new_version, transaction)
|
||||
.await
|
||||
.map_err(server_error)?;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,10 +11,7 @@ use super::device_id_header::DeviceIdHeader;
|
|||
use crate::{
|
||||
app_state::{
|
||||
AppState,
|
||||
database::{
|
||||
InsertBroadcast,
|
||||
models::{DocumentId, DocumentVersionWithoutContent, StoredDocumentVersion, VaultId},
|
||||
},
|
||||
database::models::{DocumentId, DocumentVersionWithoutContent, StoredDocumentVersion, VaultId},
|
||||
},
|
||||
config::user_config::User,
|
||||
errors::{SyncServerError, not_found_error, server_error, write_transaction_error},
|
||||
|
|
@ -101,17 +98,7 @@ pub async fn delete_document(
|
|||
|
||||
state
|
||||
.database
|
||||
.insert_document_version(
|
||||
&vault_id,
|
||||
&new_version,
|
||||
transaction,
|
||||
InsertBroadcast {
|
||||
// Deletion is a content change peers must learn about.
|
||||
content_changed: true,
|
||||
// Delete never renames.
|
||||
path_changed: false,
|
||||
},
|
||||
)
|
||||
.insert_document_version(&vault_id, &new_version, transaction)
|
||||
.await
|
||||
.map_err(server_error)?;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ use crate::{
|
|||
app_state::{
|
||||
AppState,
|
||||
database::{
|
||||
InsertBroadcast, WriteTransaction,
|
||||
WriteTransaction,
|
||||
models::{DocumentId, StoredDocumentVersion, VaultId, VaultUpdateId},
|
||||
},
|
||||
},
|
||||
|
|
@ -292,14 +292,6 @@ pub async fn update_document(
|
|||
latest_version.relative_path.clone()
|
||||
};
|
||||
|
||||
let content_changed = merged_content != latest_version.content;
|
||||
// Stored path differs from either the prior stored path (peers need
|
||||
// to learn about the rename) or from the path the origin sent
|
||||
// (origin needs to learn if its rename was deduped or rejected by
|
||||
// first-rename-wins).
|
||||
let path_changed = new_relative_path != latest_version.relative_path
|
||||
|| new_relative_path != sanitized_relative_path;
|
||||
|
||||
let new_version = StoredDocumentVersion {
|
||||
document_id,
|
||||
vault_update_id: last_update_id + 1,
|
||||
|
|
@ -315,15 +307,7 @@ pub async fn update_document(
|
|||
|
||||
state
|
||||
.database
|
||||
.insert_document_version(
|
||||
&vault_id,
|
||||
&new_version,
|
||||
transaction,
|
||||
InsertBroadcast {
|
||||
content_changed,
|
||||
path_changed,
|
||||
},
|
||||
)
|
||||
.insert_document_version(&vault_id, &new_version, transaction)
|
||||
.await
|
||||
.map_err(server_error)?;
|
||||
|
||||
|
|
|
|||
|
|
@ -134,19 +134,21 @@ async fn websocket(
|
|||
}
|
||||
};
|
||||
|
||||
send_update_over_websocket(
|
||||
&WebSocketServerMessage::VaultUpdate(WebSocketVaultUpdate {
|
||||
documents: get_unseen_documents(
|
||||
&state,
|
||||
&vault_id,
|
||||
authed_handshake.handshake.last_seen_vault_update_id,
|
||||
)
|
||||
.await?,
|
||||
is_initial_sync: true,
|
||||
}),
|
||||
&mut sender,
|
||||
// Catch-up on versions committed while this client was offline,
|
||||
// streamed one-at-a-time in ascending `vault_update_id` order
|
||||
let unseen_documents = get_unseen_documents(
|
||||
&state,
|
||||
&vault_id,
|
||||
authed_handshake.handshake.last_seen_vault_update_id,
|
||||
)
|
||||
.await?;
|
||||
for document in unseen_documents {
|
||||
send_update_over_websocket(
|
||||
&WebSocketServerMessage::VaultUpdate(WebSocketVaultUpdate { document }),
|
||||
&mut sender,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
send_update_over_websocket(
|
||||
&WebSocketServerMessage::CursorPositions(CursorPositionFromServer {
|
||||
|
|
@ -161,6 +163,8 @@ async fn websocket(
|
|||
loop {
|
||||
match broadcast_receiver.recv().await {
|
||||
Ok(update) => {
|
||||
// Drop messages this device authored because the HTTP
|
||||
// response already carried authoritative state back.
|
||||
if Some(&device_id) == update.origin_device_id.as_ref() {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -174,8 +178,7 @@ async fn websocket(
|
|||
.filter(|client| client.device_id != device_id)
|
||||
.collect(),
|
||||
}),
|
||||
WebSocketServerMessage::VaultUpdate(_)
|
||||
| WebSocketServerMessage::PathChange(_) => update.message,
|
||||
WebSocketServerMessage::VaultUpdate(_) => update.message,
|
||||
};
|
||||
|
||||
send_update_over_websocket(&message, &mut sender).await?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue