perf(home): 冷启动提前拉取首页数据
This commit is contained in:
1 parent
1199db760f
commit
9b31d83e39
7 files changed
+255
-113
No files matched your search
@@ -28,6 +28,12 @@ class AppConfig {
|
||||
|
||||
static String _runtimeBaseUrl = '';
|
||||
|
||||
static Future<void>? _ready;
|
||||
|
||||
/// 启动地址探测完成信号;默认已完成,避免影响既有测试与调用方。
|
||||
static Future<void> get ready => _ready ?? Future<void>.value();
|
||||
static set ready(Future<void> value) => _ready = value;
|
||||
|
||||
static const Duration _probeTimeout = Duration(seconds: 2);
|
||||
static const List<String> _probeCandidates = [
|
||||
lanBaseUrl,
|
||||
@@ -85,10 +91,15 @@ class AppConfig {
|
||||
for (final candidate in _probeCandidates)
|
||||
if (candidate != _runtimeBaseUrl) candidate,
|
||||
];
|
||||
for (final candidate in candidates) {
|
||||
final result = probe == null
|
||||
? await _probeBaseUrl(candidate)
|
||||
: await _runInjectedProbe(candidate, probe);
|
||||
final results = await Future.wait([
|
||||
for (final candidate in candidates)
|
||||
probe == null
|
||||
? _probeBaseUrl(candidate)
|
||||
: _runInjectedProbe(candidate, probe),
|
||||
]);
|
||||
for (var index = 0; index < candidates.length; index++) {
|
||||
final candidate = candidates[index];
|
||||
final result = results[index];
|
||||
if (kDebugMode) {
|
||||
final status = result.ok
|
||||
? 'ok'
|
||||
|
||||
Reference in new issue
Block a user