diff --git a/frontend/sync-client/src/services/sync-service.ts b/frontend/sync-client/src/services/sync-service.ts index 82303bce..99ee79ad 100644 --- a/frontend/sync-client/src/services/sync-service.ts +++ b/frontend/sync-client/src/services/sync-service.ts @@ -68,27 +68,21 @@ export class SyncService { public async create({ relativePath, contentBytes, - forceMerge }: { relativePath: RelativePath; contentBytes: Uint8Array; - forceMerge?: boolean; }): Promise { return this.retryForever(async () => { const formData = new FormData(); formData.append("relative_path", relativePath); - if (forceMerge === true) { - formData.append("force_merge", "true"); - } - formData.append( "content", new Blob([new Uint8Array(contentBytes)]) ); this.logger.debug( - `Creating document with relative path ${relativePath} (forceMerge: ${forceMerge})` + `Creating document with relative path ${relativePath}` ); const response = await this.client(this.getUrl("/documents"), { diff --git a/frontend/sync-client/src/sync-client.ts b/frontend/sync-client/src/sync-client.ts index 04a69fc9..23989dfc 100644 --- a/frontend/sync-client/src/sync-client.ts +++ b/frontend/sync-client/src/sync-client.ts @@ -369,9 +369,7 @@ export class SyncClient { this.checkIfDestroyed("syncLocallyCreatedFile"); this.fileChangeNotifier.notifyOfFileChange(relativePath); - return this.syncer.syncLocallyCreatedFile(relativePath, { - forceMerge: false - }); + return this.syncer.syncLocallyCreatedFile(relativePath,); } public async syncLocallyDeletedFile( diff --git a/frontend/sync-client/src/sync-operations/syncer.ts b/frontend/sync-client/src/sync-operations/syncer.ts index 068c348a..31efce0e 100644 --- a/frontend/sync-client/src/sync-operations/syncer.ts +++ b/frontend/sync-client/src/sync-operations/syncer.ts @@ -82,7 +82,6 @@ export class Syncer { public async syncLocallyCreatedFile( relativePath: RelativePath, - { forceMerge }: { forceMerge: boolean } ): Promise { if ( this.database.getLatestDocumentByRelativePath(relativePath) @@ -231,7 +230,7 @@ export class Syncer { await this.syncQueue.add(async () => this.unrestrictedSyncer.unrestrictedSyncLocallyCreatedOrUpdatedFile({ oldPath, - document: document! + document }) ); @@ -441,7 +440,7 @@ export class Syncer { } } - type Instruction = { "type": "update" | "create", relativePath: string, oldPath?: string }; + interface Instruction { "type": "update" | "create", relativePath: string, oldPath?: string } const instructions: (Instruction | undefined)[] = await awaitAll( allLocalFiles.map(async (relativePath) => { if ( @@ -536,10 +535,10 @@ export class Syncer { if (instruction.type === "update") { // We're outside of the pqueue, so we need to call the public wrapper - return await this.syncLocallyUpdatedFile({ + await this.syncLocallyUpdatedFile({ oldPath: instruction.oldPath, relativePath: instruction.relativePath - }); + }); return; } })); @@ -553,7 +552,7 @@ export class Syncer { if (instruction.type === "create") { // We're outside of the pqueue, so we need to call the public wrapper - return await this.syncLocallyCreatedFile(instruction.relativePath, { forceMerge: true }); + await this.syncLocallyCreatedFile(instruction.relativePath,); return; } })); diff --git a/frontend/sync-client/src/sync-operations/unrestricted-syncer.ts b/frontend/sync-client/src/sync-operations/unrestricted-syncer.ts index 272668c4..f29e19c8 100644 --- a/frontend/sync-client/src/sync-operations/unrestricted-syncer.ts +++ b/frontend/sync-client/src/sync-operations/unrestricted-syncer.ts @@ -66,14 +66,12 @@ export class UnrestrictedSyncer { public async unrestrictedSyncLocallyCreatedOrUpdatedFile({ oldPath, document, - forceMerge, // We use the same code path for both local and remote updates. We need to force the update // if there are no local changes but we know that the remote version is newer. force = false }: { oldPath?: RelativePath; force?: boolean; - forceMerge?: boolean document: DocumentRecord; }): Promise { @@ -128,7 +126,6 @@ export class UnrestrictedSyncer { const response = await this.syncService.create({ relativePath: originalRelativePath, contentBytes, - forceMerge }); await this.handleMaybeMergingResponse({ diff --git a/sync-server/src/server/create_document.rs b/sync-server/src/server/create_document.rs index e4b3c055..a5ab451f 100644 --- a/sync-server/src/server/create_document.rs +++ b/sync-server/src/server/create_document.rs @@ -49,35 +49,33 @@ pub async fn create_document( let sanitized_relative_path = sanitize_path(&request.relative_path); - if request.force_merge.unwrap_or_default() { - let latest_version = state - .database - .get_latest_non_deleted_document_by_path( - &vault_id, - &sanitized_relative_path, - Some(&mut transaction), - ) - .await - .map_err(server_error)?; - if let Some(latest_version) = latest_version { - info!( - "Document already exists at new location: `{sanitized_relative_path}` when trying to create it in vault `{vault_id}`, merging into existing document" - ); + let latest_version = state + .database + .get_latest_non_deleted_document_by_path( + &vault_id, + &sanitized_relative_path, + Some(&mut transaction), + ) + .await + .map_err(server_error)?; + if let Some(latest_version) = latest_version { + info!( + "Document already exists at new location: `{sanitized_relative_path}` when trying to create it in vault `{vault_id}`, merging into existing document" + ); - return merge_with_stored_version( - &sanitized_relative_path, - &Vec::new(), - latest_version, - vault_id, - user, - device_id, - state, - &sanitized_relative_path, - request.content.contents.to_vec(), - transaction, - ) - .await; - } + return merge_with_stored_version( + &sanitized_relative_path, + &Vec::new(), + latest_version, + vault_id, + user, + device_id, + state, + &sanitized_relative_path, + request.content.contents.to_vec(), + transaction, + ) + .await; } let document_id = uuid::Uuid::new_v4(); diff --git a/sync-server/src/server/requests.rs b/sync-server/src/server/requests.rs index 400ececf..386e682d 100644 --- a/sync-server/src/server/requests.rs +++ b/sync-server/src/server/requests.rs @@ -11,9 +11,6 @@ use crate::app_state::database::models::VaultUpdateId; pub struct CreateDocumentVersion { pub relative_path: String, - // whether to merge with existing document at the same path if it already exists - pub force_merge: Option, - #[ts(as = "Vec")] #[form_data(limit = "unlimited")] pub content: FieldData,