Skip to content

Commit

Permalink
feat: use WAL mode for databases
Browse files Browse the repository at this point in the history
  • Loading branch information
blakebyrnes committed Jan 4, 2023
1 parent d3b06b8 commit 0830238
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/dbs/NetworkDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export default class NetworkDb {
constructor() {
NetworkDb.createDir();
this.db = new Database(NetworkDb.databasePath);
this.db.unsafeMode(false)
this.db.pragma('journal_mode = WAL');
this.certificates = new CertificatesTable(this.db);
this.saveInterval = setInterval(this.flush.bind(this), 5e3).unref();

Expand Down
2 changes: 2 additions & 0 deletions core/dbs/SessionDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export default class SessionDb {
const { readonly = false, fileMustExist = false } = dbOptions;
this.sessionId = sessionId;
this.db = new Database(`${SessionDb.databaseDir}/${sessionId}.db`, { readonly, fileMustExist });
this.db.unsafeMode(false);
this.db.pragma('journal_mode = WAL');
if (!readonly) {
this.saveInterval = setInterval(this.flush.bind(this), 5e3).unref();
}
Expand Down
2 changes: 2 additions & 0 deletions core/dbs/SessionsDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export default class SessionsDb {
SessionsDb.createDir();
const { readonly = false, fileMustExist = false } = dbOptions;
this.db = new Database(SessionsDb.databasePath, { readonly, fileMustExist });
this.db.unsafeMode(false);
this.db.pragma('journal_mode = WAL');
this.readonly = readonly;
this.sessions = new SessionsTable(this.db);
}
Expand Down

0 comments on commit 0830238

Please sign in to comment.