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

Function purgeOldEvents

telemetry-worker/src/rollup.ts:239–251  ·  view source on GitHub ↗
(env: Env, cutoff: string)

Source from the content-addressed store, hash-verified

237 * keyset subquery stays a cheap index range scan on (day, event).
238 */
239export async function purgeOldEvents(env: Env, cutoff: string): Promise<PurgeResult> {
240 const del = env.DB.prepare(
241 `DELETE FROM events WHERE id IN (SELECT id FROM events WHERE day < ? LIMIT ${PURGE_BATCH_ROWS})`,
242 );
243 let deleted = 0;
244 for (let batch = 1; batch <= PURGE_MAX_BATCHES; batch++) {
245 const { meta } = await del.bind(cutoff).run();
246 const removed = meta?.changes ?? 0;
247 deleted += removed;
248 if (removed < PURGE_BATCH_ROWS) return { cutoff, deleted, batches: batch, capped: false };
249 }
250 return { cutoff, deleted, batches: PURGE_MAX_BATCHES, capped: true };
251}
252
253/**
254 * The cron body: roll up the completed day and the two before it, then purge.

Callers 1

runNightlyFunction · 0.85

Calls 2

prepareMethod · 0.65
runMethod · 0.65

Tested by

no test coverage detected