(envVal: string | undefined, dbSizeBytes?: number)
| 62 | * override; non-numeric / non-positive values fall back to the default. |
| 63 | */ |
| 64 | export function resolveWalValveMb(envVal: string | undefined, dbSizeBytes?: number): number { |
| 65 | if (envVal !== undefined && envVal !== '') { |
| 66 | const n = Number(envVal); |
| 67 | if (Number.isFinite(n) && n > 0) return Math.floor(n); |
| 68 | } |
| 69 | // Scale with the project when the caller knows the DB size: every fold |
| 70 | // re-writes hot B-tree pages into the main file (the #1231 pathology in |
| 71 | // bounded form — 111s of a kernel-scale batch loop at the flat 256MB cap, |
| 72 | // §7a.2), so a big project affords a proportionally bigger transient WAL |
| 73 | // (~dbSize/4 soft ⇒ file cap ≈ dbSize) in exchange for ~4× fewer folds. |
| 74 | if (dbSizeBytes !== undefined && dbSizeBytes > 0) { |
| 75 | return Math.min(2048, Math.max(DEFAULT_WAL_VALVE_MB, Math.floor(dbSizeBytes / 4 / (1024 * 1024)))); |
| 76 | } |
| 77 | return DEFAULT_WAL_VALVE_MB; |
| 78 | } |
| 79 | |
| 80 | export class WalCheckpointValve { |
| 81 | private timer: ReturnType<typeof setInterval> | null = null; |
no outgoing calls
no test coverage detected