@@ -582,23 +582,21 @@ class HostedSource extends CachedSource {
582582 final Map <String , dynamic > body;
583583 final List <Advisory >? result;
584584 try {
585- bodyText = await cache.hostedCache.advisoriesDownloadPool.withResource (
586- () async {
587- return await withAuthenticatedClient (cache, Uri .parse (hostedUrl), (
588- client,
589- ) async {
590- return await retryForHttp (
591- 'fetching advisories for "$packageName " from "$url "' ,
592- () async {
593- final request = http.Request ('GET' , url);
594- request.attachPubApiHeaders ();
595- final response = await client.fetch (request);
596- return response.body;
597- },
598- );
599- });
600- },
601- );
585+ bodyText = await cache.hostedCache.pool.withResource (() async {
586+ return await withAuthenticatedClient (cache, Uri .parse (hostedUrl), (
587+ client,
588+ ) async {
589+ return await retryForHttp (
590+ 'fetching advisories for "$packageName " from "$url "' ,
591+ () async {
592+ final request = http.Request ('GET' , url);
593+ request.attachPubApiHeaders ();
594+ final response = await client.fetch (request);
595+ return response.body;
596+ },
597+ );
598+ });
599+ });
602600 final decoded = jsonDecode (bodyText);
603601 if (decoded is ! Map <String , dynamic >) {
604602 throw const FormatException ('security advisories must be a mapping' );
@@ -2177,6 +2175,9 @@ int? _parseCrc32c(Map<String, String> headers, String fileName) {
21772175
21782176/// State that is cached for the HostedSource.
21792177final class HostedSourceCache {
2178+ /// A pool to rate-limit concurrent network requests to pub.dev.
2179+ final Pool pool;
2180+
21802181 /// The scheduler used to fetch version information for packages.
21812182 ///
21822183 /// This allows rate-limiting requests and speculative pre-fetching of
@@ -2196,12 +2197,11 @@ final class HostedSourceCache {
21962197 /// An in-memory cache to store the futures of fetched security advisories.
21972198 final Map <PackageId , Future <List <Advisory >?>> _advisoriesCache = {};
21982199
2199- /// A pool to rate-limit concurrent security advisory network downloads.
2200- final Pool advisoriesDownloadPool = Pool (8 );
2200+ HostedSourceCache (HostedSource hosted) : this ._(hosted, Pool (10 ));
22012201
2202- HostedSourceCache (HostedSource hosted)
2202+ HostedSourceCache ._ (HostedSource hosted, this .pool )
22032203 : scheduler = RateLimitedScheduler (
22042204 (HostedRefAndCache refAndCache) => hosted.fetchVersions (refAndCache),
2205- maxConcurrentOperations : 10 ,
2205+ pool : pool ,
22062206 );
22072207}
0 commit comments