* 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, readOnly = false)
| 34 | * (e.g. the git-hook `codegraph sync` running while the MCP server writes). |
| 35 | */ |
| 36 | function configureConnection(db: SqliteDatabase, readOnly = false): void { |
| 37 | db.pragma('busy_timeout = 5000'); // MUST be first — see above |
| 38 | db.pragma('foreign_keys = ON'); |
| 39 | if (!readOnly) db.pragma('journal_mode = WAL'); // node:sqlite supports WAL on every platform |
| 40 | db.pragma('synchronous = NORMAL'); // safe with WAL mode |
| 41 | db.pragma('cache_size = -64000'); // 64 MB page cache |
| 42 | db.pragma('temp_store = MEMORY'); // temp tables in memory |
| 43 | db.pragma(`mmap_size = ${MMAP_SIZE_BYTES}`); // memory-mapped I/O |
| 44 | // Without a journal_size_limit the -wal file never shrinks below its |
| 45 | // high-water mark while a connection lives: checkpoints fold frames back but |
| 46 | // leave the file at full size, so one giant deferred-sync WAL stays giant |
| 47 | // forever. With the limit set, any checkpoint that resets the WAL truncates |
| 48 | // the file back down. Killed-process leftovers are handled separately by |
| 49 | // healOversizedWal() at open. (#1431) |
| 50 | db.pragma(`journal_size_limit = ${WAL_HEAL_THRESHOLD_BYTES}`); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Run the rest of an open on the connection `db`. Its first statements read |
no test coverage detected