diff options
Diffstat (limited to 'src/lib/db/index.ts')
-rw-r--r-- | src/lib/db/index.ts | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/lib/db/index.ts b/src/lib/db/index.ts index a767f70..5c13f85 100644 --- a/src/lib/db/index.ts +++ b/src/lib/db/index.ts @@ -21,10 +21,29 @@ class DatabaseHandler { constructor() { const dbPath = "/home/y/code/bun/ssr/waku/bulkdata/prosody.db"; const db = new Database(dbPath, { create: true }); + + // Performance optimizations for SQLite db.exec("PRAGMA journal_mode = WAL"); // Enable Write-Ahead Logging for better performance db.exec("PRAGMA foreign_keys = ON"); + db.exec("PRAGMA cache_size = -8000"); // Increase cache size to 8MB + db.exec("PRAGMA temp_store = MEMORY"); // Store temp tables in memory + db.exec("PRAGMA synchronous = NORMAL"); // Slightly less safe but faster + this.db = db; + + // Apply performance indexes + try { + const indexesFile = Bun.file( + "/home/y/code/bun/ssr/waku/src/lib/db/indexes.sql", + ); + const indexesSql = indexesFile.text().then((txt) => { + db.exec(txt); + }); + } catch (e) { + console.error("Failed to apply performance indexes:", e); + } } + async init() { const file = Bun.file("./schema.sql"); const sql = await file.text(); |