Skip to content

Commit 35a02b9

Browse files
committed
fix: code review fixes
Signed-off-by: Mouad BANI <mouad-mb@outlook.com>
1 parent dd132b7 commit 35a02b9

5 files changed

Lines changed: 44 additions & 33 deletions

File tree

services/apps/packages_worker/src/config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ export function getGoConfig() {
7272

7373
export function getNuGetConfig() {
7474
return {
75-
batchSize: parseInt(process.env.NUGET_FETCHER_BATCH_SIZE ?? '500', 10),
76-
concurrency: parseInt(process.env.NUGET_FETCHER_CONCURRENCY ?? '8', 10),
77-
groupDelayMs: parseInt(process.env.NUGET_FETCHER_GROUP_DELAY_MS ?? '250', 10),
75+
batchSize: parseInt(process.env.NUGET_FETCHER_BATCH_SIZE ?? '1000', 10),
76+
concurrency: parseInt(process.env.NUGET_FETCHER_CONCURRENCY ?? '20', 10),
77+
groupDelayMs: parseInt(process.env.NUGET_FETCHER_GROUP_DELAY_MS ?? '0', 10),
7878
isCritical: (process.env.NUGET_FETCHER_IS_CRITICAL ?? 'false') === 'true',
7979
userAgent: process.env.NUGET_USER_AGENT,
8080
}

services/apps/packages_worker/src/nuget/client.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import axios from 'axios'
22

3-
import { NuGetFetchError, NuGetRegistrationIndex, NuGetRegistrationPage, NuGetSearchItem } from './types'
3+
import {
4+
NuGetFetchError,
5+
NuGetRegistrationIndex,
6+
NuGetRegistrationPage,
7+
NuGetSearchItem,
8+
} from './types'
49

510
const SERVICE_INDEX_URL = 'https://api.nuget.org/v3/index.json'
611

services/apps/packages_worker/src/nuget/normalize.ts

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,16 @@ export function normalizeNuGetPackage(
6565
)
6666

6767
const description =
68-
searchResult?.description ||
69-
searchResult?.summary ||
70-
latestListedEntry?.description ||
71-
null
72-
73-
const homepage =
74-
searchResult?.projectUrl || latestListedEntry?.projectUrl || null
75-
76-
const declaredRepositoryUrl =
77-
latestEntry4License?.repository?.url
78-
? latestEntry4License.repository.url
79-
: null
68+
searchResult?.description || searchResult?.summary || latestListedEntry?.description || null
69+
70+
const homepage = searchResult?.projectUrl || latestListedEntry?.projectUrl || null
71+
72+
const declaredRepositoryUrl = latestEntry4License?.repository?.url
73+
? latestEntry4License.repository.url
74+
: null
8075
const repositoryUrl = normalizeRepoUrl(declaredRepositoryUrl)
8176

82-
const keywords =
83-
searchResult?.tags && searchResult.tags.length > 0 ? searchResult.tags : null
77+
const keywords = searchResult?.tags && searchResult.tags.length > 0 ? searchResult.tags : null
8478

8579
let status: 'active' | 'deprecated' | 'unpublished'
8680
if (listedEntries.length === 0) {
@@ -93,23 +87,20 @@ export function normalizeNuGetPackage(
9387

9488
const publishedDates = allEntries
9589
.filter((e) => e.published)
96-
.map((e) => new Date(e.published!))
90+
.map((e) => new Date(e.published as string))
9791
.filter((d) => !isNaN(d.getTime()))
9892
.sort((a, b) => a.getTime() - b.getTime())
9993

10094
const firstReleaseAt = publishedDates.length > 0 ? publishedDates[0] : null
10195

10296
const latestEntry4Date = latestListedEntry ?? latestEntry
103-
const latestReleaseAt =
104-
latestEntry4Date?.published ? new Date(latestEntry4Date.published) : null
97+
const latestReleaseAt = latestEntry4Date?.published ? new Date(latestEntry4Date.published) : null
10598

10699
const totalDownloads = searchResult?.totalDownloads ?? 0
107100

108101
const owners = searchResult?.owners ?? []
109102

110-
const authors = parseAuthors(
111-
searchResult?.authors ?? latestEntry4License?.authors,
112-
)
103+
const authors = parseAuthors(searchResult?.authors ?? latestEntry4License?.authors)
113104

114105
const searchVersionMap = new Map<string, number>()
115106
if (searchResult?.versions) {

services/apps/packages_worker/src/nuget/runNuGetEnrichmentLoop.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,11 @@ async function processPackage(
193193
return 'processed'
194194
}
195195

196-
export async function processBatch(qx: QueryExecutor, config: NuGetConfig, today: string): Promise<BatchResult> {
196+
export async function processBatch(
197+
qx: QueryExecutor,
198+
config: NuGetConfig,
199+
today: string,
200+
): Promise<BatchResult> {
197201
const packages = await listNuGetPackagesToSync(qx, {
198202
limit: config.batchSize,
199203
isCritical: config.isCritical,

services/libs/data-access-layer/src/osspckgs/nuget.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { QueryExecutor } from '../queryExecutor'
21
import { insertDailyDownloads } from '../packages/downloadsDaily'
32
import { 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

3737
export 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

Comments
 (0)