@@ -25,10 +25,10 @@ export interface Last30dCandidate {
2525// BREADTH selection. A purl is "due for the latest window" while its breadth watermark
2626// (`downloads_30d_last_run_at`) is older than this run's cutoff (or absent). The watermark
2727// is bumped once its current 30-day window is refreshed, so the monthly run touches every
28- // package's latest window exactly once and the denormalized number lands across the whole
29- // universe before any deep history is filled. Older history is a separate pass keyed on
30- // `downloads_30d_history_backfilled_at` — see getNpmUniversePurlsDueForLast30dHistory .
31- export async function getNpmUniversePurlsDueForLatest30d (
28+ // package's latest window exactly once and the denormalized number lands across all npm
29+ // packages before any deep history is filled. Older history is a separate pass keyed on
30+ // `downloads_30d_history_backfilled_at` — see getNpmPurlsDueForLast30dHistory .
31+ export async function getNpmPurlsDueForLatest30d (
3232 qx : QueryExecutor ,
3333 cutoff : string ,
3434 batchSize : number ,
@@ -39,7 +39,7 @@ export async function getNpmUniversePurlsDueForLatest30d(
3939 `WITH due AS (
4040 SELECT p.purl AS purl, p.first_release_at
4141 FROM packages p
42- LEFT JOIN npm_package_universe_state s ON s.purl = p.purl
42+ LEFT JOIN npm_package_state s ON s.purl = p.purl
4343 WHERE p.ecosystem = 'npm'
4444 AND (((hashtext(p.purl) % $(laneCount)) + $(laneCount)) % $(laneCount)) = $(laneIndex)
4545 AND (s.downloads_30d_last_run_at IS NULL
@@ -61,7 +61,7 @@ export async function getNpmUniversePurlsDueForLatest30d(
6161// not yet been filled (`downloads_30d_history_backfilled_at IS NULL`). This keeps the work
6262// strictly breadth-first per package: history is never fetched before the latest window.
6363// Sharded the same way; oldest-breadth-first so the longest-waiting packages drain first.
64- export async function getNpmUniversePurlsDueForLast30dHistory (
64+ export async function getNpmPurlsDueForLast30dHistory (
6565 qx : QueryExecutor ,
6666 batchSize : number ,
6767 laneIndex : number ,
@@ -71,9 +71,8 @@ export async function getNpmUniversePurlsDueForLast30dHistory(
7171 `WITH due AS (
7272 SELECT p.purl AS purl, p.first_release_at, s.downloads_30d_last_run_at AS last_run_at
7373 FROM packages p
74- JOIN npm_package_universe_state s ON s.purl = p.purl
74+ JOIN npm_package_state s ON s.purl = p.purl
7575 WHERE p.ecosystem = 'npm'
76- AND p.is_critical = TRUE
7776 AND (((hashtext(p.purl) % $(laneCount)) + $(laneCount)) % $(laneCount)) = $(laneIndex)
7877 AND s.downloads_30d_last_run_at IS NOT NULL
7978 AND s.downloads_30d_history_backfilled_at IS NULL
@@ -90,7 +89,7 @@ export async function getNpmUniversePurlsDueForLast30dHistory(
9089}
9190
9291// Structured outcome of a last-30d run, stored as JSONB in
93- // npm_package_universe_state .downloads_30d_run_result.
92+ // npm_package_state .downloads_30d_run_result.
9493export interface Last30dRunResult {
9594 status : 'success' | 'error'
9695 httpStatus ?: number
@@ -107,7 +106,7 @@ export async function markLast30dProcessed(
107106 result : Last30dRunResult ,
108107) : Promise < void > {
109108 await qx . result (
110- `INSERT INTO npm_package_universe_state (purl, downloads_30d_last_run_at, downloads_30d_run_result)
109+ `INSERT INTO npm_package_state (purl, downloads_30d_last_run_at, downloads_30d_run_result)
111110 VALUES ($(purl), NOW(), $(result)::jsonb)
112111 ON CONFLICT (purl) DO UPDATE SET
113112 downloads_30d_last_run_at = NOW(),
@@ -126,7 +125,7 @@ export async function markLast30dHistoryBackfilled(
126125 result : Last30dRunResult ,
127126) : Promise < void > {
128127 await qx . result (
129- `UPDATE npm_package_universe_state
128+ `UPDATE npm_package_state
130129 SET downloads_30d_history_backfilled_at = NOW(),
131130 downloads_30d_run_result = $(result)::jsonb
132131 WHERE purl = $(purl)` ,
0 commit comments