use sparse io fir partial sync in case when file is used

This commit is contained in:
Nikita Sivukhin
2025-11-12 14:20:26 +04:00
parent a25e3e76eb
commit 2d517f9fd7
5 changed files with 55 additions and 15 deletions

View File

@@ -224,6 +224,10 @@ export type GeneratorResponse =
| { type: 'SyncEngineStats', operations: number, mainWal: number, revertWal: number, lastPullUnixTime?: number, lastPushUnixTime?: number, revision?: string, networkSentBytes: number, networkReceivedBytes: number }
| { type: 'SyncEngineChanges', changes: SyncEngineChanges }
export type JsPartialBootstrapStrategy =
| { type: 'Prefix', length: number }
| { type: 'Query', query: string }
export type JsProtocolRequest =
| { type: 'Http', method: string, path: string, body?: Array<number>, headers: Array<[string, string]> }
| { type: 'FullRead', path: string }
@@ -241,7 +245,7 @@ export interface SyncEngineOpts {
protocolVersion?: SyncEngineProtocolVersion
bootstrapIfEmpty: boolean
remoteEncryption?: string
partial?: boolean
partialBoostrapStrategy?: JsPartialBootstrapStrategy
}
export declare const enum SyncEngineProtocolVersion {

View File

@@ -31,7 +31,7 @@ test('partial sync', async () => {
path: ':memory:',
url: process.env.VITE_TURSO_DB_URL,
longPollTimeoutMs: 100,
partial: true,
partialBootstrapStrategy: { kind: 'prefix', length: 128 * 1024 },
});
// 128 pages plus some overhead (very rough estimation)

View File

@@ -50,6 +50,17 @@ class Database extends DatabasePromise {
return;
}
let partialBoostrapStrategy = undefined;
if (opts.partialBootstrapStrategy != null) {
switch (opts.partialBootstrapStrategy.kind) {
case "prefix":
partialBoostrapStrategy = { type: "Prefix", length: opts.partialBootstrapStrategy.length };
break;
case "query":
partialBoostrapStrategy = { type: "Query", length: opts.partialBootstrapStrategy.query };
break;
}
}
const engine = new SyncEngine({
path: opts.path,
clientName: opts.clientName,
@@ -59,7 +70,7 @@ class Database extends DatabasePromise {
tracing: opts.tracing,
bootstrapIfEmpty: typeof opts.url != "function" || opts.url() != null,
remoteEncryption: opts.remoteEncryption?.cipher,
partial: opts.partial,
partialBoostrapStrategy: partialBoostrapStrategy
});
let headers: { [K: string]: string } | (() => Promise<{ [K: string]: string }>);