diff --git a/src/lib/db/core.ts b/src/lib/db/core.ts index 69bd022ca5..f4e80e1754 100644 --- a/src/lib/db/core.ts +++ b/src/lib/db/core.ts @@ -1163,6 +1163,7 @@ export function getDbInstance(): SqliteDatabase { db.pragma("busy_timeout = 2000"); db.pragma("synchronous = NORMAL"); db.pragma(`cache_size = -${DEFAULT_DATABASE_SETTINGS.optimization.cacheSize}`); + db.pragma("temp_store = MEMORY"); db.exec(SCHEMA_SQL); ensureProviderConnectionsColumns(db); ensureUsageHistoryColumns(db); diff --git a/tests/unit/db-core-temp-store-pragma.test.ts b/tests/unit/db-core-temp-store-pragma.test.ts new file mode 100644 index 0000000000..3b23f67049 --- /dev/null +++ b/tests/unit/db-core-temp-store-pragma.test.ts @@ -0,0 +1,21 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; + +const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omr-temp-store-")); +process.env.DATA_DIR = TEST_DATA_DIR; +process.env.API_KEY_SECRET = "test-temp-store-secret"; + +const { getDbInstance } = await import("../../src/lib/db/core.ts"); + +test("temp_store pragma is 2 (MEMORY) after initDb", () => { + // The database singleton should already have the pragma set by initDb(). + // This test confirms the runtime respects the setting. + const db = getDbInstance(); + const val: unknown = db.pragma("temp_store", { simple: true }); + assert.ok(typeof val === "number"); + // 2 = MEMORY (set by the new PRAGMA in initDb) + assert.equal(val, 2, "expected temp_store=2 (MEMORY) after initDb"); +});