improve jpeg streaming + optimize the shit out of db read writes for large incoming clients and connected clients.
This commit is contained in:
@@ -13,4 +13,37 @@ const dataDir = ensureDataDir();
|
||||
export const dbPath = resolve(dataDir, "overlord.db");
|
||||
export const db: TypedDatabase = new Database(dbPath) as any;
|
||||
|
||||
function numberPragmaEnv(name: string, fallback: number, min: number): number {
|
||||
const raw = process.env[name];
|
||||
if (raw === undefined || raw === "") return fallback;
|
||||
const value = Number(raw);
|
||||
if (!Number.isFinite(value) || value < min) return fallback;
|
||||
return Math.floor(value);
|
||||
}
|
||||
|
||||
function synchronousPragmaEnv(): string {
|
||||
const raw = String(process.env.OVERLORD_SQLITE_SYNCHRONOUS || "NORMAL").toUpperCase();
|
||||
if (raw === "OFF" || raw === "NORMAL" || raw === "FULL" || raw === "EXTRA") {
|
||||
return raw;
|
||||
}
|
||||
return "NORMAL";
|
||||
}
|
||||
|
||||
function applyPragma(sql: string): void {
|
||||
try {
|
||||
db.exec(sql);
|
||||
} catch (err) {
|
||||
console.warn(`[db] Failed to apply ${sql}:`, err);
|
||||
}
|
||||
}
|
||||
|
||||
applyPragma("PRAGMA journal_mode = WAL");
|
||||
applyPragma(`PRAGMA synchronous = ${synchronousPragmaEnv()}`);
|
||||
applyPragma(`PRAGMA busy_timeout = ${numberPragmaEnv("OVERLORD_SQLITE_BUSY_TIMEOUT_MS", 5000, 0)}`);
|
||||
applyPragma("PRAGMA temp_store = MEMORY");
|
||||
applyPragma(`PRAGMA cache_size = ${numberPragmaEnv("OVERLORD_SQLITE_CACHE_SIZE_KB", 32768, 1024) * -1}`);
|
||||
applyPragma(`PRAGMA mmap_size = ${numberPragmaEnv("OVERLORD_SQLITE_MMAP_SIZE_BYTES", 268435456, 0)}`);
|
||||
applyPragma(`PRAGMA wal_autocheckpoint = ${numberPragmaEnv("OVERLORD_SQLITE_WAL_AUTOCHECKPOINT", 4000, 1)}`);
|
||||
applyPragma(`PRAGMA journal_size_limit = ${numberPragmaEnv("OVERLORD_SQLITE_JOURNAL_SIZE_LIMIT_BYTES", 67108864, 0)}`);
|
||||
|
||||
console.log(`[db] Using database at: ${dbPath}`);
|
||||
|
||||
@@ -100,6 +100,9 @@ db.run(
|
||||
db.run(
|
||||
`CREATE INDEX IF NOT EXISTS idx_clients_public_key ON clients(public_key);`,
|
||||
);
|
||||
db.run(
|
||||
`CREATE INDEX IF NOT EXISTS idx_clients_hwid ON clients(hwid);`,
|
||||
);
|
||||
db.run(
|
||||
`CREATE INDEX IF NOT EXISTS idx_clients_key_fingerprint ON clients(key_fingerprint);`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user