* Who is a user, for what was stored before the ingest path recorded it: one pass * over the days that still have raw rows, oldest first, lowering each machine's * proof of install, and then one sweep that works every machine's installed day * out from its proof. Every count of users waits for it
(lane: Lane, env: Env, scan: { at: string })
| 895 | * made again if a run ends in the middle of it. |
| 896 | */ |
| 897 | async function recordInstallProof(lane: Lane, env: Env, scan: { at: string }): Promise<void> { |
| 898 | const nextDay = [ |
| 899 | env.DB.prepare(`SELECT min(day) AS day FROM events WHERE day > ?`), |
| 900 | env.DB.prepare(`SELECT min(day) AS day FROM usage_daily WHERE day > ?`), |
| 901 | ]; |
| 902 | while (scan.at !== 'sweep') { |
| 903 | if (!lane.open()) return; |
| 904 | const found = await lane.batch(nextDay.map((statement) => statement.bind(scan.at))); |
| 905 | const day = found |
| 906 | .map((r) => ((r.results ?? [])[0] as { day?: string | null } | undefined)?.day ?? null) |
| 907 | .filter((d): d is string => d !== null) |
| 908 | .sort()[0]; |
| 909 | if (day === undefined) { |
| 910 | scan.at = 'sweep'; |
| 911 | break; |
| 912 | } |
| 913 | await perMachineRange(lane, env, day, INSTALL_PROOF.map((sql) => ({ sql }))); |
| 914 | scan.at = day; |
| 915 | } |
| 916 | const recordsFrom = userRecordsFrom(env); |
| 917 | for (const group of chunked(machineIdRanges(2), INSTALLED_SWEEP_BATCH)) { |
| 918 | if (!lane.open()) return; |
| 919 | await lane.batch(group.map(([from, before]) => env.DB.prepare(INSTALLED_DAY_FOR_RANGE).bind(from, before, recordsFrom))); |
| 920 | } |
| 921 | scan.at = 'done'; |
| 922 | } |
| 923 | |
| 924 | /** Days checked per round trip: each is one count over that day's entries in the `machine_days` day index. */ |
| 925 | const CHECK_BATCH = 8; |
no test coverage detected