* Lightweight maintenance to run after bulk writes (indexAll, sync). * Two operations: * * - `PRAGMA optimize` — incremental ANALYZE; SQLite only re-analyzes * tables whose row counts changed materially since the last * ANALYZE. Without it, the query planner has no statistic
()
| 904 | * CLI has already disarmed its watchdog). |
| 905 | */ |
| 906 | async runMaintenance(): Promise<void> { |
| 907 | // In-memory / test databases: nothing worth a worker round-trip. |
| 908 | if (!this.dbPath || this.dbPath === ':memory:') { |
| 909 | try { this.db.exec('PRAGMA optimize'); } catch { /* ignore */ } |
| 910 | try { this.db.exec('PRAGMA wal_checkpoint(PASSIVE)'); } catch { /* ignore */ } |
| 911 | return; |
| 912 | } |
| 913 | await this.runPragmasOffThread( |
| 914 | ['PRAGMA analysis_limit=1000', 'PRAGMA optimize', 'PRAGMA wal_checkpoint(PASSIVE)'], |
| 915 | // Worker threads unavailable — bounded in-line fallback, no checkpoint. |
| 916 | ['PRAGMA analysis_limit=1000', 'PRAGMA optimize'] |
| 917 | ); |
| 918 | } |
| 919 | |
| 920 | /** |
| 921 | * Run pragmas on a worker thread against its own connection to this DB |
no test coverage detected