Skip to content

Commit

Permalink
feat: parallelize initializeDB.ts promises
Browse files Browse the repository at this point in the history
  • Loading branch information
doprz committed Apr 18, 2023
1 parent fcfda3a commit 9f1dcc6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/views/lib/database/initializeDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ export async function initializeDB(): Promise<Database> {
if (db) {
return db;
}
const { Database } = await initSqlJs({
locateFile: file => WASM_FILE_URL,

const databasePromise = await initSqlJs({
locateFile: () => WASM_FILE_URL,
});
const dbBufferPromise = await fetch(DB_FILE_URL).then(res => res.arrayBuffer());
const [database, dbBuffer] = await Promise.all([databasePromise, dbBufferPromise]);

const dbBuffer = await fetch(DB_FILE_URL).then(res => res.arrayBuffer());
db = new Database(new Uint8Array(dbBuffer));
db = new database.Database(new Uint8Array(dbBuffer));

return db;
}

0 comments on commit 9f1dcc6

Please sign in to comment.