mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-05 23:02:10 +03:00
perf(db): add temp_store=MEMORY pragma to SQLite init (#6921)
* perf(db): add temp_store=MEMORY pragma to SQLite init Store temp tables/indices in memory instead of disk for faster query execution (GROUP BY, ORDER BY, subquery materialization). The two other optimized PRAGMAs (synchronous=NORMAL, cache_size=-16384) were already set. * test(db): add temp_store MEMORY pragma test Verifies PRAGMA temp_store = 2 (MEMORY) after initDb() runs. --------- Co-authored-by: oyi77 <oyi77@users.noreply.github.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
21
tests/unit/db-core-temp-store-pragma.test.ts
Normal file
21
tests/unit/db-core-temp-store-pragma.test.ts
Normal file
@@ -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");
|
||||
});
|
||||
Reference in New Issue
Block a user