MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / recordInstallProof

Function recordInstallProof

telemetry-worker/src/rollup.ts:897–922  ·  view source on GitHub ↗

* 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 })

Source from the content-addressed store, hash-verified

895 * made again if a run ends in the middle of it.
896 */
897async 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. */
925const CHECK_BATCH = 8;

Callers 1

runScheduledFunction · 0.85

Calls 9

perMachineRangeFunction · 0.85
userRecordsFromFunction · 0.85
chunkedFunction · 0.85
machineIdRangesFunction · 0.85
mapMethod · 0.80
bindMethod · 0.80
prepareMethod · 0.65
openMethod · 0.65
batchMethod · 0.45

Tested by

no test coverage detected