Fix syncing when network latency is present (#4)
* WIP * Add debug * Dedupe inserts * Add deterministic ordering * Fix whitespaces * Update insta * Add integration test script * Rename * Add test * Working for non-deletes * omg it mostly works for deletes * Isdeleted fix * remove created dates * update api * Take document id * No max attempt * works * Use string uuids * . * working!!!! (hopefully) * Improve bundling * Add module * lint * . * lint * Fix CI * use toolchain * clean up * Add useSlowFileEvents * Delete fuzz * Fix CI * use docker * fix script * clean up * Clean up * change node version * Build docker image on every commit * fix ci * 1 db per vault * Add scritps folder * Bump versions * Lint * . * Fix tests for real * Style * . * try * Consistent ordering * Fix tests * hmm * . * Clean up diff * Fixes * . * Fix version bump * . * . * .
This commit is contained in:
parent
bcf48c428d
commit
8b8f1d91d9
91 changed files with 2252 additions and 1586 deletions
15
frontend/sync-client/src/utils/create-promise.ts
Normal file
15
frontend/sync-client/src/utils/create-promise.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
export function createPromise<T = void>(): [
|
||||
Promise<T>,
|
||||
(value: T) => void,
|
||||
(error: unknown) => void
|
||||
] {
|
||||
let resolve: undefined | ((resolved: T) => void) = undefined;
|
||||
let reject: undefined | ((error: unknown) => void) = undefined;
|
||||
|
||||
const creationPromise = new Promise<T>(
|
||||
(resolve_, reject_) => ((resolve = resolve_), (reject = reject_))
|
||||
);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
return [creationPromise, resolve!, reject!];
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
import type { DocumentMetadata, RelativePath } from "src/persistence/database";
|
||||
import { EMPTY_HASH } from "./hash";
|
||||
|
||||
export function findMatchingFileBasedOnHash(
|
||||
contentHash: string,
|
||||
candidates: [RelativePath, DocumentMetadata][]
|
||||
): [RelativePath, DocumentMetadata] | undefined {
|
||||
if (contentHash === EMPTY_HASH) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return candidates.find(([_, metadata]) => metadata.hash === contentHash);
|
||||
}
|
||||
14
frontend/sync-client/src/utils/find-matching-file.ts
Normal file
14
frontend/sync-client/src/utils/find-matching-file.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import type { DocumentRecord } from "../persistence/database";
|
||||
import { EMPTY_HASH } from "./hash";
|
||||
|
||||
// TODO: make this smarter so that offline files can be renamed & edited at the same time
|
||||
export function findMatchingFile(
|
||||
contentHash: string,
|
||||
candidates: DocumentRecord[]
|
||||
): DocumentRecord | undefined {
|
||||
if (contentHash === EMPTY_HASH) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return candidates.find(({ metadata }) => metadata?.hash === contentHash);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ export function hash(content: Uint8Array): string {
|
|||
result = (result << 5) - result + content[i];
|
||||
result |= 0; // Convert to 32bit integer
|
||||
}
|
||||
return Math.abs(result).toString(16);
|
||||
return Math.abs(result).toString(16).padStart(8, "0");
|
||||
}
|
||||
|
||||
export const EMPTY_HASH = hash(new Uint8Array(0));
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import * as fetchRetryFactory from "fetch-retry";
|
||||
import type { RequestInitRetryParams } from "fetch-retry";
|
||||
import type { Logger } from "src/tracing/logger";
|
||||
import type { Logger } from "../tracing/logger";
|
||||
|
||||
function getUrlFromInput(input: RequestInfo | URL): string {
|
||||
if (input instanceof URL) {
|
||||
|
|
@ -31,7 +31,6 @@ export function retriedFetchFactory(
|
|||
}
|
||||
return false;
|
||||
},
|
||||
retries: 6,
|
||||
retryDelay: (attempt) => Math.pow(1.5, attempt) * 500,
|
||||
...init
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue