MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / configureConnection

Function configureConnection

src/db/index.ts:30–45  ·  view source on GitHub ↗

* Apply connection-level PRAGMAs. Shared by `initialize` and `open` so the two * paths can't drift. * * `busy_timeout` is set FIRST, before any pragma that might touch the database * file (notably `journal_mode`). If another process holds a write lock at open * time, the later pragmas — and the

(db: SqliteDatabase)

Source from the content-addressed store, hash-verified

28 * (e.g. the git-hook `codegraph sync` running while the MCP server writes).
29 */
30function configureConnection(db: SqliteDatabase): void {
31 db.pragma('busy_timeout = 5000'); // MUST be first — see above
32 db.pragma('foreign_keys = ON');
33 db.pragma('journal_mode = WAL'); // node:sqlite supports WAL on every platform
34 db.pragma('synchronous = NORMAL'); // safe with WAL mode
35 db.pragma('cache_size = -64000'); // 64 MB page cache
36 db.pragma('temp_store = MEMORY'); // temp tables in memory
37 db.pragma('mmap_size = 268435456'); // 256 MB memory-mapped I/O
38 // Without a journal_size_limit the -wal file never shrinks below its
39 // high-water mark while a connection lives: checkpoints fold frames back but
40 // leave the file at full size, so one giant deferred-sync WAL stays giant
41 // forever. With the limit set, any checkpoint that resets the WAL truncates
42 // the file back down. Killed-process leftovers are handled separately by
43 // healOversizedWal() at open. (#1431)
44 db.pragma(`journal_size_limit = ${WAL_HEAL_THRESHOLD_BYTES}`);
45}
46
47/**
48 * WAL size past which `healOversizedWal` (run at every `open`) checkpoints and

Callers 2

initializeMethod · 0.85
openMethod · 0.85

Calls 1

pragmaMethod · 0.65

Tested by

no test coverage detected