(lane: Lane, env: Env)
| 1226 | } |
| 1227 | |
| 1228 | async function loadState(lane: Lane, env: Env): Promise<RunState> { |
| 1229 | const rows = await lane.all<{ key: string; value: string }>( |
| 1230 | env.DB.prepare( |
| 1231 | `SELECT key, value FROM rollup_state |
| 1232 | WHERE key IN ('regular', 'windows', 'cohorts', 'checked', 'proof_scan', 'proof_records_from')`, |
| 1233 | ), |
| 1234 | ); |
| 1235 | const byKey = new Map(rows.map((r) => [r.key, r.value])); |
| 1236 | let installedScan = byKey.get('proof_scan') ?? ''; |
| 1237 | // The installed days were worked out with another beginning of the records |
| 1238 | // (USER_RECORDS_FROM was moved): the proof stands, and the days are worked out again. |
| 1239 | if (installedScan === 'done' && byKey.get('proof_records_from') !== userRecordsFrom(env)) installedScan = 'sweep'; |
| 1240 | return { |
| 1241 | regular: stamps(byKey.get('regular')), |
| 1242 | windows: stamps(byKey.get('windows')), |
| 1243 | cohorts: byKey.get('cohorts') ?? '', |
| 1244 | checked: byKey.get('checked') ?? '', |
| 1245 | installedScan, |
| 1246 | }; |
| 1247 | } |
| 1248 | |
| 1249 | const STATE_UPSERT = `INSERT INTO rollup_state (key, value, updated_at) VALUES (?, ?, ?) |
| 1250 | ON CONFLICT (key) DO UPDATE SET value = excluded.value, updated_at = excluded.updated_at`; |
no test coverage detected