Skip to content

Commit d3e84eb

Browse files
committed
perf: early-return on HTTPS success in probeAndNormalizeUrl
1 parent b3790b7 commit d3e84eb

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/providers/api_provider.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,11 @@ Future<ProbeResult> probeAndNormalizeUrl(String url, Future<String?> Function(St
166166
if (!hasHttpScheme(url)) {
167167
final httpsUrl = normalizeUrl('https://$url');
168168
final httpUrl = normalizeUrl('http://$url');
169-
final results = await Future.wait([probeFn(httpsUrl), probeFn(httpUrl)]);
170-
final probed = results[0] ?? results[1];
171-
return (url: probed ?? httpsUrl, probed: probed != null);
169+
final httpFuture = probeFn(httpUrl);
170+
final httpsResult = await probeFn(httpsUrl);
171+
if (httpsResult != null) return (url: httpsResult, probed: true);
172+
final httpResult = await httpFuture;
173+
return (url: httpResult ?? httpsUrl, probed: httpResult != null);
172174
}
173175
return (url: normalizeUrl(url), probed: true);
174176
}

0 commit comments

Comments
 (0)