@@ -87,7 +87,6 @@ void registerSearchIndex(SearchIndex index) =>
8787class SearchBackend {
8888 final DatastoreDB _db;
8989 final VersionedJsonStorage _snapshotStorage;
90- final _http = httpRetryClient ();
9190
9291 SearchBackend (this ._db, Bucket snapshotBucket)
9392 : _snapshotStorage = VersionedJsonStorage (snapshotBucket, 'snapshot/' );
@@ -428,42 +427,6 @@ class SearchBackend {
428427 }
429428 }
430429
431- /// Downloads the remote SDK content from [uri] and creates a cached file in the
432- /// `.dart_tool/pub-search-data/` directory.
433- ///
434- /// When a local file in `app/.dart_tool/pub-search-data/<reduced-uri>` exists,
435- /// its content will be loaded instead. URL reduction replaces slashes and other
436- /// non-characters with a single dash `-` , like:
437- /// - `https-api.dart.dev-stable-latest-index.json`
438- Future <String > loadOrFetchSdkIndexJsonAsString (
439- Uri uri, {
440- @visibleForTesting Duration ? ttl,
441- }) async {
442- final fileName = uri.toString ().replaceAll (RegExp (r'[^a-z0-9\.]+' ), '-' );
443- final file = File (p.join ('.dart_tool' , 'pub-search-data' , fileName));
444- if (await file.exists ()) {
445- var canUseCached = true ;
446- if (ttl != null ) {
447- final age = clock.now ().difference (await file.lastModified ());
448- if (age > ttl) {
449- canUseCached = false ;
450- }
451- }
452- if (canUseCached) {
453- return await file.readAsString ();
454- }
455- }
456-
457- final rs = await _http.get (uri);
458- if (rs.statusCode != 200 ) {
459- throw Exception ('Unexpected status code for $uri : ${rs .statusCode }' );
460- }
461- final content = rs.body;
462- await file.parent.create (recursive: true );
463- await file.writeAsString (content);
464- return content;
465- }
466-
467430 Future <List <PackageDocument >?> fetchSnapshotDocuments () async {
468431 try {
469432 final map = await _snapshotStorage.getContentAsJsonMap ();
@@ -519,7 +482,6 @@ class SearchBackend {
519482
520483 Future <void > close () async {
521484 _snapshotStorage.close ();
522- _http.close ();
523485 }
524486}
525487
@@ -615,6 +577,38 @@ List<ApiDocPage> apiDocPagesFromPubData(PubDartdocData pubData) {
615577 return results;
616578}
617579
580+ /// Downloads the remote SDK content from [uri] and creates a cached file in the
581+ /// `.dart_tool/pub-search-data/` directory.
582+ ///
583+ /// When a local file in `app/.dart_tool/pub-search-data/<reduced-uri>` exists,
584+ /// its content will be loaded instead. URL reduction replaces slashes and other
585+ /// non-characters with a single dash `-` , like:
586+ /// - `https-api.dart.dev-stable-latest-index.json`
587+ Future <String > loadOrFetchSdkIndexJsonAsString (
588+ Uri uri, {
589+ @visibleForTesting Duration ? ttl,
590+ }) async {
591+ final fileName = uri.toString ().replaceAll (RegExp (r'[^a-z0-9\.]+' ), '-' );
592+ final file = File (p.join ('.dart_tool' , 'pub-search-data' , fileName));
593+ if (await file.exists ()) {
594+ var canUseCached = true ;
595+ if (ttl != null ) {
596+ final age = clock.now ().difference (await file.lastModified ());
597+ if (age > ttl) {
598+ canUseCached = false ;
599+ }
600+ }
601+ if (canUseCached) {
602+ return await file.readAsString ();
603+ }
604+ }
605+
606+ final content = await httpGetWithRetry (uri, responseFn: (rs) => rs.body);
607+ await file.parent.create (recursive: true );
608+ await file.writeAsString (content);
609+ return content;
610+ }
611+
618612class _CombinedSearchIndex implements SearchIndex {
619613 const _CombinedSearchIndex ();
620614
0 commit comments