perf(export): optimize SQL export performance
This commit is contained in:
1 parent
7fd4aef060
commit
605d20dd4f
14 files changed
+665
-293
No files matched your search
@@ -66,6 +66,12 @@ export interface AllDatabaseExportPlanItem {
|
||||
displayName: string;
|
||||
}
|
||||
|
||||
export interface DatabaseBackupSnapshotOptions {
|
||||
connectionId: string;
|
||||
database: string;
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
export function buildInsertStatements(options: BuildExportInsertStatementsOptions): Promise<string[]> {
|
||||
return api.buildExportInsertStatements(options);
|
||||
}
|
||||
@@ -100,6 +106,23 @@ export async function runDatabaseExportUntilTerminal(request: api.DatabaseExport
|
||||
});
|
||||
}
|
||||
|
||||
export async function runWithDatabaseBackupSnapshot<T>(options: DatabaseBackupSnapshotOptions, operation: (snapshotSessionId: string | undefined) => Promise<T>, shouldPropagateCleanupError: (result: T) => boolean = () => true): Promise<T> {
|
||||
if (!options.enabled) return operation(undefined);
|
||||
|
||||
const snapshot = await api.beginDatabaseBackupSnapshot(options.connectionId, options.database);
|
||||
let result: T | undefined;
|
||||
let operationCompleted = false;
|
||||
try {
|
||||
result = await operation(snapshot.sessionId);
|
||||
operationCompleted = true;
|
||||
return result;
|
||||
} finally {
|
||||
await api.rollbackManualTransaction(snapshot.sessionId).catch((error) => {
|
||||
if (operationCompleted && shouldPropagateCleanupError(result as T)) throw error;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function buildAllDatabaseExportPlan(options: AllDatabaseExportPlanInput): AllDatabaseExportPlanItem[] {
|
||||
return options.databases.flatMap((database) => {
|
||||
const schemas = options.schemaAware ? (options.schemasByDatabase?.[database] ?? []).filter((schema) => schema.trim()) : [database];
|
||||
|
||||
Reference in new issue
Block a user