Fetch checksum values in batches

This commit is contained in:
daz 2024-12-17 17:15:35 -07:00
parent e0475e1bea
commit 1a1961913d
No known key found for this signature in database

View File

@ -1,5 +1,6 @@
import * as httpm from 'typed-rest-client/HttpClient'
import * as cheerio from 'cheerio'
import * as core from '@actions/core'
import fileWrapperChecksums from './wrapper-checksums.json'
@ -59,12 +60,7 @@ export async function fetchUnknownChecksums(
}
const wrapperChecksums = new WrapperChecksums()
await Promise.all(
checksumUrls.map(async ([version, url]) => {
const checksum = await httpGetText(url)
wrapperChecksums.add(version, checksum)
})
)
await fetchAndStoreChecksums(checksumUrls, wrapperChecksums)
return wrapperChecksums
}
@ -94,3 +90,20 @@ async function addDistributionSnapshotChecksumUrls(checksumUrls: [string, string
}
})
}
async function fetchAndStoreChecksums(
checksumUrls: [string, string][],
wrapperChecksums: WrapperChecksums
): Promise<void> {
const batchSize = 10
for (let i = 0; i < checksumUrls.length; i += batchSize) {
const batch = checksumUrls.slice(i, i + batchSize)
await Promise.all(
batch.map(async ([version, url]) => {
const checksum = await httpGetText(url)
wrapperChecksums.add(version, checksum)
})
)
core.info(`Fetched ${i + batch.length} of ${checksumUrls.length} checksums`)
}
}