summaryrefslogtreecommitdiff
path: root/src/lib/db/index.ts
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-05-29 15:37:22 +0700
committerpolwex <polwex@sortug.com>2025-05-29 15:37:22 +0700
commitf23f7d2f0106882183929c740e4862a1939900d0 (patch)
tree8f77b63ca7e65db828e3bada68d54513acfea777 /src/lib/db/index.ts
parent8e0965f5274635f609972ef85802675af64df0f4 (diff)
me again but it works!
Diffstat (limited to 'src/lib/db/index.ts')
-rw-r--r--src/lib/db/index.ts19
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();