perf(home): 冷启动提前拉取首页数据

This commit is contained in:
Zhou Weidong committed 2026-10-20 19:51:41 +08:00
1 parent 1199db760f
commit 9b31d83e39
7 files changed
+255 -113

No files matched your search

+11 -2
View File
@@ -21,7 +21,7 @@ class ApiClient {
this.tokenRefresher,
this.onUnauthorized,
this.deviceIdReader,
}) : baseUrl = baseUrl ?? AppConfig.apiBaseUrl {
}) : _fixedBaseUrl = baseUrl {
_dio = Dio(
BaseOptions(
baseUrl: this.baseUrl,
@@ -45,9 +45,12 @@ class ApiClient {
}
}
final String baseUrl;
final String? _fixedBaseUrl;
late final Dio _dio;
/// 当前请求使用的服务地址;未显式指定时跟随启动探测结果。
String get baseUrl => _fixedBaseUrl ?? AppConfig.apiBaseUrl;
/// 取当前 access token(未登录返回 null)
final String? Function()? accessTokenReader;
@@ -110,6 +113,7 @@ class ApiClient {
bool retried = false,
bool skipAuthRetry = false,
}) async {
_syncBaseUrl();
final disableAuthRetry = skipAuthRetry || tokenRefresher == null;
try {
final response = await _dio.request<Object?>(
@@ -150,5 +154,10 @@ class ApiClient {
}
}
void _syncBaseUrl() {
if (_fixedBaseUrl != null) return;
_dio.options.baseUrl = AppConfig.apiBaseUrl;
}
void close() => _dio.close(force: true);
}
@@ -35,6 +35,7 @@ class CatalogController extends ChangeNotifier {
debugError = null;
notifyListeners();
try {
await AppConfig.ready;
feed = await repository.fetchHomeFeed();
} on ApiException catch (exception) {
error = exception.message;