From e93ce84cd57eacfe820c1f22668ed069020ee46e Mon Sep 17 00:00:00 2001 From: Priyash <38959321+priyashpatil@users.noreply.github.com> Date: Tue, 6 Aug 2024 05:08:23 +0530 Subject: [PATCH] feat: enable WAL (Write-Ahead Logging) for improved performance and stability (#1885) Enable Write-Ahead Logging (WAL) mode for the SQLite database. This change is intended to enhance both the performance and stability of database operations, particularly when handling concurrent transactions and large volumes of data. --- core/indexing/CodeSnippetsIndex.ts | 2 ++ core/indexing/FullTextSearch.ts | 2 ++ core/indexing/LanceDbIndex.ts | 2 ++ core/indexing/chunk/ChunkCodebaseIndex.ts | 2 ++ core/indexing/docs/DocsService.ts | 3 ++- core/indexing/refreshIndex.ts | 2 ++ core/util/devdataSqlite.ts | 2 ++ 7 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core/indexing/CodeSnippetsIndex.ts b/core/indexing/CodeSnippetsIndex.ts index 8fc1ccb95..1da07a3e2 100644 --- a/core/indexing/CodeSnippetsIndex.ts +++ b/core/indexing/CodeSnippetsIndex.ts @@ -28,6 +28,8 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex { constructor(private readonly ide: IDE) {} private static async _createTables(db: DatabaseConnection) { + await db.exec("PRAGMA journal_mode=WAL;"); + await db.exec(`CREATE TABLE IF NOT EXISTS code_snippets ( id INTEGER PRIMARY KEY, path TEXT NOT NULL, diff --git a/core/indexing/FullTextSearch.ts b/core/indexing/FullTextSearch.ts index c640eae20..c35b6778d 100644 --- a/core/indexing/FullTextSearch.ts +++ b/core/indexing/FullTextSearch.ts @@ -20,6 +20,8 @@ export class FullTextSearchCodebaseIndex implements CodebaseIndex { artifactId = "sqliteFts"; private async _createTables(db: DatabaseConnection) { + await db.exec("PRAGMA journal_mode=WAL;"); + await db.exec(`CREATE VIRTUAL TABLE IF NOT EXISTS fts USING fts5( path, content, diff --git a/core/indexing/LanceDbIndex.ts b/core/indexing/LanceDbIndex.ts index 3a312b719..9a5d94e07 100644 --- a/core/indexing/LanceDbIndex.ts +++ b/core/indexing/LanceDbIndex.ts @@ -46,6 +46,8 @@ export class LanceDbIndex implements CodebaseIndex { } private async createSqliteCacheTable(db: DatabaseConnection) { + await db.exec("PRAGMA journal_mode=WAL;"); + await db.exec(`CREATE TABLE IF NOT EXISTS lance_db_cache ( uuid TEXT PRIMARY KEY, cacheKey TEXT NOT NULL, diff --git a/core/indexing/chunk/ChunkCodebaseIndex.ts b/core/indexing/chunk/ChunkCodebaseIndex.ts index d80bb1c4f..d3e4e9a0d 100644 --- a/core/indexing/chunk/ChunkCodebaseIndex.ts +++ b/core/indexing/chunk/ChunkCodebaseIndex.ts @@ -24,6 +24,8 @@ export class ChunkCodebaseIndex implements CodebaseIndex { } private async _createTables(db: DatabaseConnection) { + await db.exec("PRAGMA journal_mode=WAL;"); + await db.exec(`CREATE TABLE IF NOT EXISTS chunks ( id INTEGER PRIMARY KEY AUTOINCREMENT, cacheKey TEXT NOT NULL, diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts index 4142dffa1..8f5cc6cf7 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -476,7 +476,8 @@ export default class DocsService { await runSqliteMigrations(db); - db.exec(`CREATE TABLE IF NOT EXISTS ${DocsService.sqlitebTableName} ( + await db.exec("PRAGMA journal_mode=WAL;"); + await db.exec(`CREATE TABLE IF NOT EXISTS ${DocsService.sqlitebTableName} ( id INTEGER PRIMARY KEY AUTOINCREMENT, title STRING NOT NULL, startUrl STRING NOT NULL UNIQUE, diff --git a/core/indexing/refreshIndex.ts b/core/indexing/refreshIndex.ts index 2111bc9c1..faf74b515 100644 --- a/core/indexing/refreshIndex.ts +++ b/core/indexing/refreshIndex.ts @@ -23,6 +23,8 @@ export class SqliteDb { static db: DatabaseConnection | null = null; private static async createTables(db: DatabaseConnection) { + await db.exec("PRAGMA journal_mode=WAL;"); + await db.exec( `CREATE TABLE IF NOT EXISTS tag_catalog ( id INTEGER PRIMARY KEY AUTOINCREMENT, diff --git a/core/util/devdataSqlite.ts b/core/util/devdataSqlite.ts index 9724e9f21..4a8ab7458 100644 --- a/core/util/devdataSqlite.ts +++ b/core/util/devdataSqlite.ts @@ -8,6 +8,8 @@ export class DevDataSqliteDb { static db: DatabaseConnection | null = null; private static async createTables(db: DatabaseConnection) { + await db.exec("PRAGMA journal_mode=WAL;"); + await db.exec( `CREATE TABLE IF NOT EXISTS tokens_generated ( id INTEGER PRIMARY KEY AUTOINCREMENT,