* 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
()
| 598 | * CLI has already disarmed its watchdog). |
| 599 | */ |
| 600 | async runMaintenance(): Promise<void> { |
| 601 | // In-memory / test databases: nothing worth a worker round-trip. |
| 602 | if (!this.dbPath || this.dbPath === ':memory:') { |
| 603 | try { this.db.exec('PRAGMA optimize'); } catch { /* ignore */ } |
| 604 | try { this.db.exec('PRAGMA wal_checkpoint(PASSIVE)'); } catch { /* ignore */ } |
| 605 | return; |
| 606 | } |
| 607 | await this.runPragmasOffThread( |
| 608 | ['PRAGMA analysis_limit=1000', 'PRAGMA optimize', 'PRAGMA wal_checkpoint(PASSIVE)'], |
| 609 | // Worker threads unavailable — bounded in-line fallback, no checkpoint. |
| 610 | ['PRAGMA analysis_limit=1000', 'PRAGMA optimize'] |
| 611 | ); |
| 612 | } |
| 613 | |
| 614 | /** |
| 615 | * Run pragmas on a worker thread against its own connection to this DB |
no test coverage detected