Remove force_merge flag
This commit is contained in:
parent
bd8650e80b
commit
ea5a123cb8
6 changed files with 33 additions and 50 deletions
|
|
@ -68,27 +68,21 @@ export class SyncService {
|
||||||
public async create({
|
public async create({
|
||||||
relativePath,
|
relativePath,
|
||||||
contentBytes,
|
contentBytes,
|
||||||
forceMerge
|
|
||||||
}: {
|
}: {
|
||||||
relativePath: RelativePath;
|
relativePath: RelativePath;
|
||||||
contentBytes: Uint8Array;
|
contentBytes: Uint8Array;
|
||||||
forceMerge?: boolean;
|
|
||||||
}): Promise<DocumentUpdateResponse> {
|
}): Promise<DocumentUpdateResponse> {
|
||||||
return this.retryForever(async () => {
|
return this.retryForever(async () => {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
formData.append("relative_path", relativePath);
|
formData.append("relative_path", relativePath);
|
||||||
if (forceMerge === true) {
|
|
||||||
formData.append("force_merge", "true");
|
|
||||||
}
|
|
||||||
|
|
||||||
formData.append(
|
formData.append(
|
||||||
"content",
|
"content",
|
||||||
new Blob([new Uint8Array(contentBytes)])
|
new Blob([new Uint8Array(contentBytes)])
|
||||||
);
|
);
|
||||||
|
|
||||||
this.logger.debug(
|
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"), {
|
const response = await this.client(this.getUrl("/documents"), {
|
||||||
|
|
|
||||||
|
|
@ -369,9 +369,7 @@ export class SyncClient {
|
||||||
this.checkIfDestroyed("syncLocallyCreatedFile");
|
this.checkIfDestroyed("syncLocallyCreatedFile");
|
||||||
|
|
||||||
this.fileChangeNotifier.notifyOfFileChange(relativePath);
|
this.fileChangeNotifier.notifyOfFileChange(relativePath);
|
||||||
return this.syncer.syncLocallyCreatedFile(relativePath, {
|
return this.syncer.syncLocallyCreatedFile(relativePath,);
|
||||||
forceMerge: false
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async syncLocallyDeletedFile(
|
public async syncLocallyDeletedFile(
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,6 @@ export class Syncer {
|
||||||
|
|
||||||
public async syncLocallyCreatedFile(
|
public async syncLocallyCreatedFile(
|
||||||
relativePath: RelativePath,
|
relativePath: RelativePath,
|
||||||
{ forceMerge }: { forceMerge: boolean }
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (
|
if (
|
||||||
this.database.getLatestDocumentByRelativePath(relativePath)
|
this.database.getLatestDocumentByRelativePath(relativePath)
|
||||||
|
|
@ -231,7 +230,7 @@ export class Syncer {
|
||||||
await this.syncQueue.add(async () =>
|
await this.syncQueue.add(async () =>
|
||||||
this.unrestrictedSyncer.unrestrictedSyncLocallyCreatedOrUpdatedFile({
|
this.unrestrictedSyncer.unrestrictedSyncLocallyCreatedOrUpdatedFile({
|
||||||
oldPath,
|
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(
|
const instructions: (Instruction | undefined)[] = await awaitAll(
|
||||||
allLocalFiles.map(async (relativePath) => {
|
allLocalFiles.map(async (relativePath) => {
|
||||||
if (
|
if (
|
||||||
|
|
@ -536,10 +535,10 @@ export class Syncer {
|
||||||
|
|
||||||
if (instruction.type === "update") {
|
if (instruction.type === "update") {
|
||||||
// We're outside of the pqueue, so we need to call the public wrapper
|
// We're outside of the pqueue, so we need to call the public wrapper
|
||||||
return await this.syncLocallyUpdatedFile({
|
await this.syncLocallyUpdatedFile({
|
||||||
oldPath: instruction.oldPath,
|
oldPath: instruction.oldPath,
|
||||||
relativePath: instruction.relativePath
|
relativePath: instruction.relativePath
|
||||||
});
|
}); return;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
@ -553,7 +552,7 @@ export class Syncer {
|
||||||
|
|
||||||
if (instruction.type === "create") {
|
if (instruction.type === "create") {
|
||||||
// We're outside of the pqueue, so we need to call the public wrapper
|
// 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;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,14 +66,12 @@ export class UnrestrictedSyncer {
|
||||||
public async unrestrictedSyncLocallyCreatedOrUpdatedFile({
|
public async unrestrictedSyncLocallyCreatedOrUpdatedFile({
|
||||||
oldPath,
|
oldPath,
|
||||||
document,
|
document,
|
||||||
forceMerge,
|
|
||||||
// We use the same code path for both local and remote updates. We need to force the update
|
// 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.
|
// if there are no local changes but we know that the remote version is newer.
|
||||||
force = false
|
force = false
|
||||||
}: {
|
}: {
|
||||||
oldPath?: RelativePath;
|
oldPath?: RelativePath;
|
||||||
force?: boolean;
|
force?: boolean;
|
||||||
forceMerge?: boolean
|
|
||||||
document: DocumentRecord;
|
document: DocumentRecord;
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
|
|
||||||
|
|
@ -128,7 +126,6 @@ export class UnrestrictedSyncer {
|
||||||
const response = await this.syncService.create({
|
const response = await this.syncService.create({
|
||||||
relativePath: originalRelativePath,
|
relativePath: originalRelativePath,
|
||||||
contentBytes,
|
contentBytes,
|
||||||
forceMerge
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.handleMaybeMergingResponse({
|
await this.handleMaybeMergingResponse({
|
||||||
|
|
|
||||||
|
|
@ -49,35 +49,33 @@ pub async fn create_document(
|
||||||
|
|
||||||
let sanitized_relative_path = sanitize_path(&request.relative_path);
|
let sanitized_relative_path = sanitize_path(&request.relative_path);
|
||||||
|
|
||||||
if request.force_merge.unwrap_or_default() {
|
let latest_version = state
|
||||||
let latest_version = state
|
.database
|
||||||
.database
|
.get_latest_non_deleted_document_by_path(
|
||||||
.get_latest_non_deleted_document_by_path(
|
&vault_id,
|
||||||
&vault_id,
|
&sanitized_relative_path,
|
||||||
&sanitized_relative_path,
|
Some(&mut transaction),
|
||||||
Some(&mut transaction),
|
)
|
||||||
)
|
.await
|
||||||
.await
|
.map_err(server_error)?;
|
||||||
.map_err(server_error)?;
|
if let Some(latest_version) = latest_version {
|
||||||
if let Some(latest_version) = latest_version {
|
info!(
|
||||||
info!(
|
"Document already exists at new location: `{sanitized_relative_path}` when trying to create it in vault `{vault_id}`, merging into existing document"
|
||||||
"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(
|
return merge_with_stored_version(
|
||||||
&sanitized_relative_path,
|
&sanitized_relative_path,
|
||||||
&Vec::new(),
|
&Vec::new(),
|
||||||
latest_version,
|
latest_version,
|
||||||
vault_id,
|
vault_id,
|
||||||
user,
|
user,
|
||||||
device_id,
|
device_id,
|
||||||
state,
|
state,
|
||||||
&sanitized_relative_path,
|
&sanitized_relative_path,
|
||||||
request.content.contents.to_vec(),
|
request.content.contents.to_vec(),
|
||||||
transaction,
|
transaction,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let document_id = uuid::Uuid::new_v4();
|
let document_id = uuid::Uuid::new_v4();
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,6 @@ use crate::app_state::database::models::VaultUpdateId;
|
||||||
pub struct CreateDocumentVersion {
|
pub struct CreateDocumentVersion {
|
||||||
pub relative_path: String,
|
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>")]
|
#[ts(as = "Vec<u8>")]
|
||||||
#[form_data(limit = "unlimited")]
|
#[form_data(limit = "unlimited")]
|
||||||
pub content: FieldData<Bytes>,
|
pub content: FieldData<Bytes>,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue