Skip to content

Commit 63a94ee

Browse files
committed
2 parents f9f4439 + 4f870ae commit 63a94ee

5 files changed

Lines changed: 32 additions & 17 deletions

File tree

scripts/test-chunk-consistency.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@ console.log(`Created: ${createdDate}`)
4848
console.log('')
4949

5050
// Simulate running on different days
51-
const testDates = [
52-
'2025-12-06',
53-
'2025-12-07',
54-
'2025-12-08',
55-
]
51+
const testDates = ['2025-12-06', '2025-12-07', '2025-12-08']
5652

5753
console.log('Testing chunk consistency across different "today" dates:\n')
5854

@@ -122,17 +118,25 @@ const lastChunks = dates.map((date) => {
122118
return chunks[chunks.length - 1]
123119
})
124120

125-
console.log(` Run 1 (${dates[0]}): ${lastChunks[0].from}${lastChunks[0].to}`)
126-
console.log(` Run 2 (${dates[1]}): ${lastChunks[1].from}${lastChunks[1].to}`)
127-
console.log(` Run 3 (${dates[2]}): ${lastChunks[2].from}${lastChunks[2].to}`)
121+
console.log(
122+
` Run 1 (${dates[0]}): ${lastChunks[0].from}${lastChunks[0].to}`,
123+
)
124+
console.log(
125+
` Run 2 (${dates[1]}): ${lastChunks[1].from}${lastChunks[1].to}`,
126+
)
127+
console.log(
128+
` Run 3 (${dates[2]}): ${lastChunks[2].from}${lastChunks[2].to}`,
129+
)
128130

129131
const currentChunksDiffer = lastChunks[0].to !== lastChunks[1].to
130132
console.log('')
131133
if (currentChunksDiffer) {
132134
console.log(
133135
'✅ Current chunks differ (expected - they track "today" and will be marked mutable)',
134136
)
135-
console.log(' These chunks expire in 6 hours and get refreshed with updated data')
137+
console.log(
138+
' These chunks expire in 6 hours and get refreshed with updated data',
139+
)
136140
} else {
137141
console.log('⚠️ Current chunks are identical (might be same day)')
138142
}

scripts/test-npm-cache.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ async function testCache() {
2525
testDateFrom,
2626
testDateTo,
2727
)
28-
console.log(` Result: ${miss === null ? '✅ NULL (as expected)' : '❌ Got data (unexpected)'}`)
28+
console.log(
29+
` Result: ${miss === null ? '✅ NULL (as expected)' : '❌ Got data (unexpected)'}`,
30+
)
2931

3032
// Test 2: Write to cache
3133
console.log('\nTest 2: Write to cache')
@@ -84,7 +86,9 @@ async function testCache() {
8486
historicalDateTo,
8587
)
8688
if (historical) {
87-
console.log(` Is immutable: ${historical.isImmutable ? '✅ YES (as expected)' : '❌ NO (unexpected)'}`)
89+
console.log(
90+
` Is immutable: ${historical.isImmutable ? '✅ YES (as expected)' : '❌ NO (unexpected)'}`,
91+
)
8892
} else {
8993
console.log(' ❌ Failed to retrieve historical chunk')
9094
}

src/utils/stats-admin.server.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,9 @@ export const refreshAllNpmStats = createServerFn({ method: 'POST' })
396396
}),
397397
)
398398
.handler(async ({ data }) => {
399-
console.log(`[Admin] refreshAllNpmStats handler called with org: ${data.org}`)
399+
console.log(
400+
`[Admin] refreshAllNpmStats handler called with org: ${data.org}`,
401+
)
400402

401403
await requireCapability({ data: { capability: 'admin' } })
402404

src/utils/stats-db.server.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,10 @@ export async function getCachedNpmDownloadChunk(
10291029
dateTo: cached.dateTo,
10301030
binSize: cached.binSize,
10311031
totalDownloads: cached.totalDownloads,
1032-
dailyData: cached.dailyData as Array<{ day: string; downloads: number }>,
1032+
dailyData: cached.dailyData as Array<{
1033+
day: string
1034+
downloads: number
1035+
}>,
10331036
isImmutable: cached.isImmutable,
10341037
}
10351038
}
@@ -1042,7 +1045,10 @@ export async function getCachedNpmDownloadChunk(
10421045
dateTo: cached.dateTo,
10431046
binSize: cached.binSize,
10441047
totalDownloads: cached.totalDownloads,
1045-
dailyData: cached.dailyData as Array<{ day: string; downloads: number }>,
1048+
dailyData: cached.dailyData as Array<{
1049+
day: string
1050+
downloads: number
1051+
}>,
10461052
isImmutable: cached.isImmutable,
10471053
}
10481054
}

src/utils/stats.functions.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,8 @@ async function fetchNpmPackageDownloadsChunked(
457457
let lastChunkData: { day: string; downloads: number }[] = []
458458

459459
// Load cache functions (dynamic import for Netlify compatibility)
460-
const { getCachedNpmDownloadChunk, setCachedNpmDownloadChunk } = await import(
461-
'./stats-db.server'
462-
)
460+
const { getCachedNpmDownloadChunk, setCachedNpmDownloadChunk } =
461+
await import('./stats-db.server')
463462

464463
// Fetch chunks sequentially to avoid nested AsyncQueuer complexity
465464
// The outer queue (per-package) provides concurrency control

0 commit comments

Comments
 (0)