mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
Cancel in-flight paginated fetches to prevent stale-write races
Rapidly switching filter chips, sort columns, or pagination on the devices and notifications lists could overlap fetches, and an older response landing after a newer one would silently overwrite the list with results that no longer match the active query. Thread an optional CancelToken into listDevices and listNotifications. Each State now keeps one active token, cancels it on every new fetch and on dispose, and bails from both success and catch branches when its token has been superseded. DioExceptionType.cancel is silenced so internal cancellations don't surface as user-visible errors. The notifications list's prior `if (_isLoading) return;` guard is removed so the 1-min periodic refresh is no longer skipped during user activity. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
d3b6c64e8b
commit
30df22df56
@@ -142,6 +142,7 @@ class BackendAPI {
|
||||
bool? sortAscending,
|
||||
int? offset,
|
||||
int? limit,
|
||||
CancelToken? cancelToken,
|
||||
}) async {
|
||||
debugPrint('About to call /devices');
|
||||
|
||||
@@ -162,7 +163,11 @@ class BackendAPI {
|
||||
params['page_limit'] = limit ?? _pageSize;
|
||||
}
|
||||
|
||||
final response = await _dio.get('/devices', queryParameters: params);
|
||||
final response = await _dio.get(
|
||||
'/devices',
|
||||
queryParameters: params,
|
||||
cancelToken: cancelToken,
|
||||
);
|
||||
|
||||
debugPrint('Received: ${response.data}');
|
||||
|
||||
@@ -257,6 +262,7 @@ class BackendAPI {
|
||||
bool? isNew,
|
||||
int offset, {
|
||||
int? limit,
|
||||
CancelToken? cancelToken,
|
||||
}) async {
|
||||
debugPrint('About to call /notifications');
|
||||
|
||||
@@ -268,6 +274,7 @@ class BackendAPI {
|
||||
'page_offset': offset,
|
||||
'page_limit': limit ?? _pageSize,
|
||||
},
|
||||
cancelToken: cancelToken,
|
||||
);
|
||||
|
||||
debugPrint('Received: ${response.data}');
|
||||
|
||||
Reference in New Issue
Block a user