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

Method synthesizeWithWalDeferred

src/index.ts:2050–2078  ·  view source on GitHub ↗

* The rebuild, with the WAL handling a sync gives it (#1231, #1248): a whole * graph's edges rewritten must not be checkpointed inline on this thread by * the next commit on this connection, so the valve bounds the WAL off-thread * and runMaintenance folds it up.

()

Source from the content-addressed store, hash-verified

2048 * and runMaintenance folds it up.
2049 */
2050 private async synthesizeWithWalDeferred(): Promise<void> {
2051 const deferWal = process.env.CODEGRAPH_NO_WAL_DEFER !== '1' && this.db.getJournalMode() === 'wal';
2052 let walValve: WalCheckpointValve | null = null;
2053 let priorAutocheckpoint = 1000;
2054 if (deferWal) {
2055 priorAutocheckpoint = this.db.getWalAutocheckpoint();
2056 this.db.setWalAutocheckpoint(0);
2057 walValve = new WalCheckpointValve(
2058 this.db,
2059 resolveWalValveMb(process.env.CODEGRAPH_WAL_VALVE_MB, this.db.getDbFileSizeBytes())
2060 );
2061 walValve.start();
2062 }
2063 try {
2064 await this.resolver.refreshSynthesis(
2065 this.db.getPath(),
2066 undefined,
2067 walValve ? () => walValve!.backpressure() : undefined
2068 );
2069 this.queries.setMetadata('synthesis_pending', '0');
2070 this.lastSynthesisAt = Date.now();
2071 await this.db.runMaintenance();
2072 } finally {
2073 if (walValve) { walValve.stop(); await walValve.drain(); }
2074 if (deferWal) {
2075 try { this.db.setWalAutocheckpoint(priorAutocheckpoint); } catch { /* connection may be closing */ }
2076 }
2077 }
2078 }
2079
2080 // ===========================================================================
2081 // File Watching

Callers 1

runDeferredSynthesisMethod · 0.95

Calls 13

resolveWalValveMbFunction · 0.90
getWalAutocheckpointMethod · 0.80
setWalAutocheckpointMethod · 0.80
getDbFileSizeBytesMethod · 0.80
refreshSynthesisMethod · 0.80
getPathMethod · 0.80
backpressureMethod · 0.80
setMetadataMethod · 0.80
runMaintenanceMethod · 0.80
startMethod · 0.65
stopMethod · 0.65
getJournalModeMethod · 0.45

Tested by

no test coverage detected