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