mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-19 08:04:19 +01:00
use sparse io fir partial sync in case when file is used
This commit is contained in:
@@ -110,7 +110,7 @@ export interface DatabaseOpts {
|
||||
/**
|
||||
* optional parameter to enable partial sync for the database
|
||||
*/
|
||||
partial?: boolean;
|
||||
partialBootstrapStrategy?: { kind: 'prefix', length: number } | { kind: 'query', query: string };
|
||||
}
|
||||
export interface DatabaseStats {
|
||||
/**
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 }>);
|
||||
|
||||
Reference in New Issue
Block a user