feat: parallelize initializeDB.ts promises
This commit is contained in:
@@ -24,12 +24,14 @@ export async function initializeDB(): Promise<Database> {
|
|||||||
if (db) {
|
if (db) {
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
const { Database } = await initSqlJs({
|
|
||||||
locateFile: file => WASM_FILE_URL,
|
|
||||||
});
|
|
||||||
|
|
||||||
const dbBuffer = await fetch(DB_FILE_URL).then(res => res.arrayBuffer());
|
const databasePromise = await initSqlJs({
|
||||||
db = new Database(new Uint8Array(dbBuffer));
|
locateFile: () => WASM_FILE_URL,
|
||||||
|
});
|
||||||
|
const dbBufferPromise = await fetch(DB_FILE_URL).then(res => res.arrayBuffer());
|
||||||
|
const [database, dbBuffer] = await Promise.all([databasePromise, dbBufferPromise]);
|
||||||
|
|
||||||
|
db = new database.Database(new Uint8Array(dbBuffer));
|
||||||
|
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user