Clean up diff

This commit is contained in:
Andras Schmelczer 2025-03-16 19:49:09 +00:00
parent 8d695999c6
commit 10568efebe
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
6 changed files with 25 additions and 57 deletions

View file

@ -23,7 +23,6 @@ pub type Transaction<'a> = sqlx::Transaction<'a, Sqlite>;
impl Database {
pub async fn try_new(config: &DatabaseConfig) -> Result<Self> {
// Create the databases directory if it doesn't exist
tokio::fs::create_dir_all(&config.databases_directory_path)
.await
.with_context(|| {
@ -67,7 +66,6 @@ impl Database {
.databases_directory_path
.join(format!("{vault}.sqlite"));
// Continue with database connection setup
let connection_options = SqliteConnectOptions::new()
.filename(file_name.clone())
.create_if_missing(true)

View file

@ -107,7 +107,7 @@ export class FileOperations {
currentText = currentText.replace(/\r\n/g, "\n");
if (currentText !== expectedText) {
this.logger.debug(
`Performing a 3-way merge for ${path} with the expected content:\n${expectedText}`
`Performing a 3-way merge for ${path} with the expected content`
);
return mergeText(expectedText, currentText, newText);

View file

@ -452,7 +452,10 @@ export interface components {
Array_of_uint8: number[];
CreateDocumentVersion: {
contentBase64: string;
/** Format: uuid */
/**
* Format: uuid
* @description The client can decide the document id (if it wishes to) in order to help with syncing. If the client does not provide a document id, the server will generate one. If the client provides a document id it must not already exist in the database.
*/
documentId?: string | null;
relativePath: string;
};
@ -476,7 +479,6 @@ export interface components {
type: "FastForwardUpdate";
/** Format: date-time */
updatedDate: string;
vaultId: string;
/** Format: int64 */
vaultUpdateId: number;
}
@ -490,7 +492,6 @@ export interface components {
type: "MergingUpdate";
/** Format: date-time */
updatedDate: string;
vaultId: string;
/** Format: int64 */
vaultUpdateId: number;
};
@ -502,7 +503,6 @@ export interface components {
relativePath: string;
/** Format: date-time */
updatedDate: string;
vaultId: string;
/** Format: int64 */
vaultUpdateId: number;
};
@ -513,7 +513,6 @@ export interface components {
relativePath: string;
/** Format: date-time */
updatedDate: string;
vaultId: string;
/** Format: int64 */
vaultUpdateId: number;
};

View file

@ -60,24 +60,6 @@ export class Syncer {
);
}
private static async forgivingFileNotFoundWrapper<T>(
fn: () => Promise<T>,
logger: Logger
): Promise<T | undefined> {
try {
return await fn();
} catch (e) {
if (e instanceof FileNotFoundError) {
logger.debug(
`File has been deleted or moved before we had a chance to inspect it, skipping`
);
return undefined;
}
throw e;
}
}
public addRemainingOperationsListener(
listener: (remainingOperations: number) => void
): void {
@ -355,13 +337,7 @@ export class Syncer {
// Perhaps the file has been moved; let's check by looking at the deleted files
const contentHash = await this.syncQueue.add(async () => {
const contentBytes =
await Syncer.forgivingFileNotFoundWrapper(
async () => this.operations.read(relativePath),
this.logger
);
if (contentBytes === undefined) {
return;
}
await this.operations.read(relativePath); // this can throw FileNotFoundError
return hash(contentBytes);
});

View file

@ -251,10 +251,7 @@ export class MockAgent extends MockClient {
`Decided to create file ${file} with content ${content}`
);
return this.create(
file,
new TextEncoder().encode(` |${content}| `)
);
return this.create(file, new TextEncoder().encode(` ${content} `));
}
private async changeFetchChangesUpdateIntervalMsAction(): Promise<void> {
@ -328,7 +325,7 @@ export class MockAgent extends MockClient {
`Decided to update file ${file} with ${content}`
);
this.doNotTouchWhileOffline.push(file);
await this.atomicUpdateText(file, (old) => old + ` |${content}| `);
await this.atomicUpdateText(file, (old) => old + ` ${content} `);
}
private async deleteFileAction(files: RelativePath[]): Promise<void> {

View file

@ -46,10 +46,6 @@ async function runTest({
);
}
// for debugging
// eslint-disable-next-line
(globalThis as any).clients = clients;
try {
await Promise.all(clients.map(async (client) => client.init()));
@ -109,20 +105,22 @@ async function runTest({
}
async function runTests(): Promise<void> {
for (const concurrency of [
16,
1 // test with concurrency 1 to check for deadlocks
]) {
for (const doDeletes of [true, false]) {
for (const useSlowFileEvents of [true, false]) {
await runTest({
agentCount: 4,
concurrency,
iterations: 200,
doDeletes,
useSlowFileEvents,
jitterScaleInSeconds: 0.75
});
for (const useSlowFileEvents of [false, true]) {
for (const concurrency of [
16,
1 // test with concurrency 1 to check for deadlocks
]) {
for (const doDeletes of [true, false]) {
for (let i = 0; i < 4; i++) {
await runTest({
agentCount: 2,
concurrency,
iterations: 200,
doDeletes,
useSlowFileEvents,
jitterScaleInSeconds: 0.75
});
}
}
}
}
@ -148,7 +146,7 @@ runTests()
.then(() => {
process.exit(0);
})
.catch(async (err: unknown) => {
.catch((err: unknown) => {
console.error(err);
process.exit(1);
});