Remove force_merge flag

This commit is contained in:
Andras Schmelczer 2026-01-13 20:29:26 +00:00
parent bd8650e80b
commit ea5a123cb8
6 changed files with 33 additions and 50 deletions

View file

@ -68,27 +68,21 @@ export class SyncService {
public async create({
relativePath,
contentBytes,
forceMerge
}: {
relativePath: RelativePath;
contentBytes: Uint8Array;
forceMerge?: boolean;
}): Promise<DocumentUpdateResponse> {
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"), {

View file

@ -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(

View file

@ -82,7 +82,6 @@ export class Syncer {
public async syncLocallyCreatedFile(
relativePath: RelativePath,
{ forceMerge }: { forceMerge: boolean }
): Promise<void> {
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;
}
}));

View file

@ -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<void> {
@ -128,7 +126,6 @@ export class UnrestrictedSyncer {
const response = await this.syncService.create({
relativePath: originalRelativePath,
contentBytes,
forceMerge
});
await this.handleMaybeMergingResponse({

View file

@ -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();

View file

@ -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<bool>,
#[ts(as = "Vec<u8>")]
#[form_data(limit = "unlimited")]
pub content: FieldData<Bytes>,