* 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.
()
| 1992 | * and runMaintenance folds it up. |
| 1993 | */ |
| 1994 | private async synthesizeWithWalDeferred(): Promise<void> { |
| 1995 | const deferWal = process.env.CODEGRAPH_NO_WAL_DEFER !== '1' && this.db.getJournalMode() === 'wal'; |
| 1996 | let walValve: WalCheckpointValve | null = null; |
| 1997 | let priorAutocheckpoint = 1000; |
| 1998 | if (deferWal) { |
| 1999 | priorAutocheckpoint = this.db.getWalAutocheckpoint(); |
| 2000 | this.db.setWalAutocheckpoint(0); |
| 2001 | walValve = new WalCheckpointValve( |
| 2002 | this.db, |
| 2003 | resolveWalValveMb(process.env.CODEGRAPH_WAL_VALVE_MB, this.db.getDbFileSizeBytes()) |
| 2004 | ); |
| 2005 | walValve.start(); |
| 2006 | } |
| 2007 | try { |
| 2008 | await this.resolver.refreshSynthesis( |
| 2009 | this.db.getPath(), |
| 2010 | undefined, |
| 2011 | walValve ? () => walValve!.backpressure() : undefined |
| 2012 | ); |
| 2013 | this.queries.setMetadata('synthesis_pending', '0'); |
| 2014 | this.lastSynthesisAt = Date.now(); |
| 2015 | await this.db.runMaintenance(); |
| 2016 | } finally { |
| 2017 | if (walValve) { walValve.stop(); await walValve.drain(); } |
| 2018 | if (deferWal) { |
| 2019 | try { this.db.setWalAutocheckpoint(priorAutocheckpoint); } catch { /* connection may be closing */ } |
| 2020 | } |
| 2021 | } |
| 2022 | } |
| 2023 | |
| 2024 | // =========================================================================== |
| 2025 | // File Watching |
no test coverage detected