33 lines
1.3 KiB
TypeScript
33 lines
1.3 KiB
TypeScript
import Database from 'better-sqlite3';
|
|
import { enableIncrementalVacuum } from '../../src/lib/server/db/retention-clocks.js';
|
|
|
|
// Run in a separate process so native SQLite memory, not just V8's heap, is measured.
|
|
const handle = new Database(process.argv[2]);
|
|
try {
|
|
handle.pragma('journal_mode = WAL');
|
|
handle.pragma('cache_size = -16384');
|
|
handle.exec('CREATE TABLE records(id INTEGER PRIMARY KEY, content BLOB)');
|
|
const insert = handle.prepare('INSERT INTO records(content) VALUES(zeroblob(1048576))');
|
|
handle.transaction(() => {
|
|
for (let i = 0; i < 256; i++) insert.run();
|
|
})();
|
|
handle.pragma('wal_checkpoint(TRUNCATE)');
|
|
handle.pragma('shrink_memory');
|
|
// Reproduce the dangerous caller settings. The rebuild must override these.
|
|
handle.pragma('temp_store = MEMORY');
|
|
handle.pragma('cache_size = -131072');
|
|
const beforeKiB = process.resourceUsage().maxRSS;
|
|
enableIncrementalVacuum(handle);
|
|
console.log(
|
|
JSON.stringify({
|
|
beforeKiB,
|
|
peakKiB: process.resourceUsage().maxRSS,
|
|
vacuum: handle.pragma('auto_vacuum', { simple: true }),
|
|
integrity: handle.pragma('quick_check', { simple: true }),
|
|
rows: handle.prepare('SELECT COUNT(*) n FROM records').get()
|
|
})
|
|
);
|
|
} finally {
|
|
handle.close();
|
|
}
|