diff --git a/src/ipc/database/cloudHandler.ts b/src/ipc/database/cloudHandler.ts index 0d2b306..df3a936 100644 --- a/src/ipc/database/cloudHandler.ts +++ b/src/ipc/database/cloudHandler.ts @@ -22,6 +22,7 @@ function ensureDatabaseInitialized(dbPath: string): void { let db: Database.Database | null = null; try { db = new Database(dbPath); + db.pragma('journal_mode = WAL'); // Create accounts table // Storing complex objects (token, quota) as JSON strings for simplicity @@ -73,7 +74,9 @@ function ensureDatabaseInitialized(dbPath: string): void { function getDb(): Database.Database { const dbPath = getCloudAccountsDbPath(); ensureDatabaseInitialized(dbPath); - return new Database(dbPath); + const db = new Database(dbPath); + db.pragma('journal_mode = WAL'); + return db; } export class CloudAccountRepo { @@ -307,6 +310,7 @@ export class CloudAccountRepo { } const db = new Database(dbPath); + db.pragma('journal_mode = WAL'); try { const row = db .prepare('SELECT value FROM ItemTable WHERE key = ?') @@ -454,6 +458,7 @@ export class CloudAccountRepo { logger.info(`SyncLocal: Using Antigravity database at: ${dbPath}`); const ideDb = new Database(dbPath, { readonly: true }); + ideDb.pragma('journal_mode = WAL'); try { // 1. Read Raw Token Data const row = ideDb diff --git a/src/ipc/database/handler.ts b/src/ipc/database/handler.ts index bcfea75..5dbe8db 100644 --- a/src/ipc/database/handler.ts +++ b/src/ipc/database/handler.ts @@ -8,6 +8,12 @@ import path from 'path'; const KEYS_TO_BACKUP = ['antigravityAuthStatus', 'jetskiStateSync.agentManagerInitState']; +function getDbWithWal(dbPath: string, options: Database.Options = {}): Database.Database { + const db = new Database(dbPath, options); + db.pragma('journal_mode = WAL'); + return db; +} + /** * Ensures that the database file exists. * @param dbPath {string} The path to the database file. @@ -59,7 +65,7 @@ export function getDatabaseConnection(dbPath?: string): Database.Database { ensureDatabaseExists(targetPath); try { - return new Database(targetPath, { readonly: false, fileMustExist: false }); + return getDbWithWal(targetPath, { readonly: false, fileMustExist: false }); } catch (error: unknown) { const err = error as { code?: string }; if (err.code === 'SQLITE_BUSY' || err.code === 'SQLITE_LOCKED') { @@ -69,6 +75,12 @@ export function getDatabaseConnection(dbPath?: string): Database.Database { } } +/** + * Gets a database connection and enables WAL mode. + * @param dbPath {string} The path to the database file. + * @returns {Database.Database} The database connection. + */ + /** * Gets the current account info. * @returns {AccountInfo} The current account info.