feat(client): 慢请求监控(>500ms 记日志+上报);拆除列表 provider 的 _cache 失败兜底
- SlowRequestInterceptor:单次 API 调用超 500ms 即 debugPrint long-request 日志并经 ErrorReporter 上报(error_type=slow_api,按 method+归一路径 5 分钟 节流)。服务端 GIN 日志只见自身处理耗时,网络往返段只有客户端可观测。 - 拆除 10 个列表 provider 的 _cache 失败兜底:实测线上接口客户端视角典型 50-120ms、最坏约 270ms(列表类全部 <500ms),失败静默端旧数据弊大于利 (曾放大跨账号残留问题),改为明确进入错误态由用户重试。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -35,20 +35,12 @@ class InventoryListNotifier extends AsyncNotifier<PageResult<Inventory>> {
|
||||
bool _sortAsc = true;
|
||||
List<String> _series = [];
|
||||
List<String> _spec = [];
|
||||
PageResult<Inventory>? _cache;
|
||||
|
||||
@override
|
||||
Future<PageResult<Inventory>> build() async {
|
||||
ref.watch(authStateProvider.select((s) => s.user?.shopId));
|
||||
ref.watch(networkRecoveryCountProvider); // 网络恢复时自动刷新
|
||||
try {
|
||||
final result = await _fetch();
|
||||
_cache = result;
|
||||
return result;
|
||||
} catch (_) {
|
||||
if (_cache != null) return _cache!;
|
||||
rethrow;
|
||||
}
|
||||
return _fetch();
|
||||
}
|
||||
|
||||
Future<PageResult<Inventory>> _fetch() {
|
||||
@@ -125,14 +117,9 @@ class InventoryListNotifier extends AsyncNotifier<PageResult<Inventory>> {
|
||||
state = const AsyncValue<PageResult<Inventory>>.loading()
|
||||
.copyWithPrevious(state);
|
||||
_fetch().then((result) {
|
||||
_cache = result;
|
||||
state = AsyncValue.data(result);
|
||||
}, onError: (e, st) {
|
||||
if (_cache != null) {
|
||||
state = AsyncValue.data(_cache!);
|
||||
} else {
|
||||
state = AsyncValue.error(e, st);
|
||||
}
|
||||
state = AsyncValue.error(e, st);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -145,20 +132,12 @@ final inventoryLogProvider =
|
||||
class InventoryLogNotifier extends AsyncNotifier<PageResult<InventoryLog>> {
|
||||
int _page = 1;
|
||||
int _pageSize = AppConstants.defaultPageSize;
|
||||
PageResult<InventoryLog>? _cache;
|
||||
|
||||
@override
|
||||
Future<PageResult<InventoryLog>> build() async {
|
||||
ref.watch(authStateProvider.select((s) => s.user?.shopId));
|
||||
ref.watch(networkRecoveryCountProvider);
|
||||
try {
|
||||
final result = await _fetch();
|
||||
_cache = result;
|
||||
return result;
|
||||
} catch (_) {
|
||||
if (_cache != null) return _cache!;
|
||||
rethrow;
|
||||
}
|
||||
return _fetch();
|
||||
}
|
||||
|
||||
Future<PageResult<InventoryLog>> _fetch() {
|
||||
@@ -182,14 +161,9 @@ class InventoryLogNotifier extends AsyncNotifier<PageResult<InventoryLog>> {
|
||||
void reload() {
|
||||
state = const AsyncValue.loading();
|
||||
_fetch().then((result) {
|
||||
_cache = result;
|
||||
state = AsyncValue.data(result);
|
||||
}, onError: (e, st) {
|
||||
if (_cache != null) {
|
||||
state = AsyncValue.data(_cache!);
|
||||
} else {
|
||||
state = AsyncValue.error(e, st);
|
||||
}
|
||||
state = AsyncValue.error(e, st);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user