Tune SQLite caches and maintain planner statistics

This commit is contained in:
2026-10-06 14:05:02 -04:00
parent 283a553cc2
commit 18283c63a7
6 changed files with 48 additions and 0 deletions
+17
View File
@@ -9,6 +9,23 @@ beforeEach(async () => {
afterEach(async () => { await fixture.cleanup(); });
describe('prepared statement caching', () => {
it('tunes the controller connection and stops periodic optimization when closed', async () => {
const { db, closeDb } = await import('../../src/lib/server/db/index.js');
vi.useFakeTimers({ toFake: ['setInterval', 'clearInterval'] });
try {
const handle = db();
expect(handle.pragma('cache_size', { simple: true })).toBe(-131072);
expect(handle.pragma('temp_store', { simple: true })).toBe(2);
expect(handle.pragma('journal_size_limit', { simple: true })).toBe(67108864);
const pragma = vi.spyOn(handle, 'pragma');
vi.advanceTimersByTime(60 * 60_000);
expect(pragma).toHaveBeenCalledWith('optimize');
pragma.mockClear();
closeDb();
vi.advanceTimersByTime(60 * 60_000);
expect(pragma).not.toHaveBeenCalled();
} finally { vi.useRealTimers(); }
});
it('reuses statements with fresh parameters and remains usable after rollback', async () => {
const { db } = await import('../../src/lib/server/db/index.js');
const insertSql = 'INSERT INTO settings (key, value) VALUES (?, ?)';