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

Function rollupDay

telemetry-worker/src/rollup.ts:203–223  ·  view source on GitHub ↗
(
  env: Env,
  day: string,
  opts: { cutoff: string; reset?: boolean },
)

Source from the content-addressed store, hash-verified

201 * real day is the one irreversible thing this file could do.
202 */
203export async function rollupDay(
204 env: Env,
205 day: string,
206 opts: { cutoff: string; reset?: boolean },
207): Promise<DayResult> {
208 const pastRetention = day < opts.cutoff;
209 const statements: D1PreparedStatement[] = [];
210
211 if (opts.reset && !pastRetention) {
212 for (const table of EVENT_DERIVED_TABLES) {
213 statements.push(env.DB.prepare(`DELETE FROM ${table} WHERE day = ?`).bind(day));
214 }
215 }
216 for (const sql of ROLLUP_STATEMENTS) {
217 statements.push(env.DB.prepare(sql).bind(day));
218 }
219
220 const results = await env.DB.batch(statements);
221 const rows = results.reduce((total, r) => total + (r.meta?.changes ?? 0), 0);
222 return { day, rows, pastRetention };
223}
224
225export interface PurgeResult {
226 /** Everything strictly before this day was deleted. */

Callers 2

runNightlyFunction · 0.85
handleAdminRollupFunction · 0.85

Calls 1

prepareMethod · 0.65

Tested by

no test coverage detected