Tune SQLite caches and maintain planner statistics
This commit is contained in:
@@ -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 (?, ?)';
|
||||
|
||||
Reference in New Issue
Block a user