1- import { QueryExecutor } from '../queryExecutor'
21import { insertDailyDownloads } from '../packages/downloadsDaily'
32import { upsertLast30dDownload } from '../packages/downloadsLast30d'
3+ import { QueryExecutor } from '../queryExecutor'
44
55// ─── Types ────────────────────────────────────────────────────────────────────
66
@@ -30,8 +30,8 @@ export type IDbNuGetPackageUpsert = {
3030 latestReleaseAt : Date | null
3131 registryUrl : string | null
3232 ingestionSource : string
33- dependentPackagesCount ? : number | null
34- dependentReposCount ? : number | null
33+ dependentPackagesCount : number | null
34+ dependentReposCount : number | null
3535}
3636
3737export type IDbNuGetVersionUpsert = {
@@ -67,13 +67,15 @@ export async function upsertNuGetPackage(
6767 description, homepage, declared_repository_url, repository_url,
6868 licenses, licenses_raw, keywords, status,
6969 latest_version, versions_count, first_release_at, latest_release_at,
70- registry_url, ingestion_source, last_synced_at, created_at
70+ registry_url, ingestion_source, dependent_count, dependent_repos_count,
71+ last_synced_at, created_at
7172 ) VALUES (
7273 $(purl), 'nuget', NULL, $(name),
7374 $(description), $(homepage), $(declaredRepositoryUrl), $(repositoryUrl),
7475 $(licenses)::text[], $(licensesRaw), $(keywords)::text[], $(status),
7576 $(latestVersion), $(versionsCount), $(firstReleaseAt), $(latestReleaseAt),
76- $(registryUrl), $(ingestionSource), NOW(), NOW()
77+ $(registryUrl), $(ingestionSource), $(dependentPackagesCount), $(dependentReposCount),
78+ NOW(), NOW()
7779 )
7880 ON CONFLICT (purl) DO UPDATE SET
7981 description = COALESCE(EXCLUDED.description, packages.description),
@@ -90,6 +92,8 @@ export async function upsertNuGetPackage(
9092 latest_release_at = COALESCE(EXCLUDED.latest_release_at, packages.latest_release_at),
9193 registry_url = COALESCE(EXCLUDED.registry_url, packages.registry_url),
9294 ingestion_source = EXCLUDED.ingestion_source,
95+ dependent_count = COALESCE(EXCLUDED.dependent_count, packages.dependent_count),
96+ dependent_repos_count = COALESCE(EXCLUDED.dependent_repos_count, packages.dependent_repos_count),
9397 last_synced_at = NOW()
9498 RETURNING id, description, homepage, declared_repository_url, repository_url,
9599 licenses, licenses_raw, keywords, status,
@@ -132,6 +136,8 @@ export async function upsertNuGetPackage(
132136 latestReleaseAt : item . latestReleaseAt ?? null ,
133137 registryUrl : item . registryUrl ?? null ,
134138 ingestionSource : item . ingestionSource ,
139+ dependentPackagesCount : item . dependentPackagesCount ?? null ,
140+ dependentReposCount : item . dependentReposCount ?? null ,
135141 } ,
136142 )
137143 return { id : row . id as number , changedFields : row . changed_fields as string [ ] }
@@ -216,7 +222,9 @@ export async function upsertNuGetVersionsBatch(
216222 isPreleases : deduped . map ( ( v ) => v . isPrerelease ) ,
217223 isYankeds : deduped . map ( ( v ) => v . isYanked ?? null ) ,
218224 licenses : deduped . map ( ( v ) => ( v . licenses && v . licenses . length > 0 ? v . licenses [ 0 ] : null ) ) ,
219- downloadCounts : deduped . map ( ( v ) => ( v . downloadCount !== null ? Number ( v . downloadCount ) : null ) ) ,
225+ downloadCounts : deduped . map ( ( v ) =>
226+ v . downloadCount !== null ? Number ( v . downloadCount ) : null ,
227+ ) ,
220228 } ,
221229 )
222230 return row . changed_fields
@@ -277,7 +285,8 @@ export async function recordNuGetDownloadSnapshot(
277285 `SELECT total_downloads FROM packages WHERE id = $(packageId)` ,
278286 { packageId } ,
279287 )
280- const prev : number | null = prevRow ?. total_downloads ?? null
288+ const prev : number | null =
289+ prevRow ?. total_downloads != null ? Number ( prevRow . total_downloads ) : null
281290
282291 if ( prev !== null && totalDownloads > prev ) {
283292 const delta = totalDownloads - prev
@@ -288,7 +297,9 @@ export async function recordNuGetDownloadSnapshot(
288297 }
289298
290299 const updated = await qx . result (
291- `UPDATE packages SET total_downloads = $(totalDownloads) WHERE id = $(packageId) AND total_downloads IS DISTINCT FROM $(totalDownloads)` ,
300+ `UPDATE packages SET total_downloads = $(totalDownloads)
301+ WHERE id = $(packageId)
302+ AND (total_downloads IS NULL OR total_downloads < $(totalDownloads))` ,
292303 { totalDownloads, packageId } ,
293304 )
294305 if ( updated > 0 ) changed . push ( 'packages.total_downloads' )
0 commit comments