From f23f7d2f0106882183929c740e4862a1939900d0 Mon Sep 17 00:00:00 2001 From: polwex Date: Thu, 29 May 2025 15:37:22 +0700 Subject: me again but it works! --- src/lib/db/index.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/lib/db/index.ts') 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(); -- cgit v1.2.3