Skip to content

Commit c604633

Browse files
committed
chore: Updated push and pull timeouts.
1 parent 3da8a66 commit c604633

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

lib/model/backend/backend.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,18 @@ final backendClientProvider = AsyncNotifierProvider<BackendClient, Map<String, S
2323
/// Allows to communicate with the backend.
2424
class BackendClient extends AsyncNotifier<Map<String, String>> {
2525
/// The default timeout in seconds.
26-
static const int _kDefaultTimeout = 10;
26+
static const Duration _kDefaultTimeout = Duration(seconds: 10);
27+
28+
/// The app client ID storage key.
29+
static const String _kAppClientIdKey = 'appClientId';
2730

2831
/// The HTTP client instance.
2932
final http.Client _client = http.Client();
3033

3134
@override
3235
FutureOr<Map<String, String>> build() async {
3336
PackageInfo packageInfo = await PackageInfo.fromPlatform();
34-
String? appClientId = await SimpleSecureStorage.read('appClientId');
37+
String? appClientId = await SimpleSecureStorage.read(_kAppClientIdKey);
3538
ref.onDispose(_client.close);
3639
return {
3740
'App-Version': packageInfo.version,
@@ -46,7 +49,7 @@ class BackendClient extends AsyncNotifier<Map<String, String>> {
4649
if (!headers.containsKey('App-Client-Id')) {
4750
String appClientId = currentPlatform.generateAppClientId();
4851
headers['App-Client-Id'] = appClientId;
49-
await SimpleSecureStorage.write('appClientId', appClientId);
52+
await SimpleSecureStorage.write(_kAppClientIdKey, appClientId);
5053
if (ref.mounted) {
5154
state = AsyncData(headers);
5255
}
@@ -60,6 +63,7 @@ class BackendClient extends AsyncNotifier<Map<String, String>> {
6063
String? backendUrl,
6164
Session? session,
6265
bool autoRefreshAccessToken = true,
66+
Duration timeout = _kDefaultTimeout,
6367
}) async {
6468
try {
6569
bool isConnected = await ref.read(connectivityStateProvider.future);
@@ -89,7 +93,7 @@ class BackendClient extends AsyncNotifier<Map<String, String>> {
8993
).build(),
9094
headers: headers,
9195
)
92-
.timeout(const Duration(seconds: _kDefaultTimeout));
96+
.timeout(timeout);
9397
return ResultSuccess(
9498
value: request.toResponse(response),
9599
);

lib/model/backend/synchronization/queue.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ final pushOperationsQueueProvider = AsyncNotifierProvider<PushOperationsQueue, L
2525

2626
/// Allows to manage the push operations queue.
2727
class PushOperationsQueue extends AsyncNotifier<List<PushOperation>> {
28+
/// The push operation timeout.
29+
static const Duration _kPushOperationTimeout = Duration(seconds: 20);
30+
2831
@override
2932
Future<List<PushOperation>> build() async {
3033
AppDatabase database = ref.watch(appDatabaseProvider);
@@ -71,6 +74,7 @@ class PushOperationsQueue extends AsyncNotifier<List<PushOperation>> {
7174
SynchronizationPushRequest(
7275
operations: compactedOperations.reversed.toList(),
7376
),
77+
timeout: _kPushOperationTimeout,
7478
);
7579
if (result is! ResultSuccess<SynchronizationPushResponse>) {
7680
return result;
@@ -93,6 +97,9 @@ final synchronizationControllerProvider = NotifierProvider<SynchronizationContro
9397

9498
/// Allows to control the synchronization process.
9599
class SynchronizationController extends Notifier<SynchronizationStatus> with WidgetsBindingObserver {
100+
/// The synchronization pull timeout.
101+
static const Duration _kPullTimeout = Duration(seconds: 20);
102+
96103
/// The synchronization periodic interval.
97104
static const Duration _kPeriodicInterval = Duration(minutes: 10);
98105

@@ -301,6 +308,7 @@ class SynchronizationController extends Notifier<SynchronizationStatus> with Wid
301308
},
302309
deleted: deletedTotps,
303310
),
311+
timeout: _kPullTimeout,
304312
);
305313

306314
if (result is! ResultSuccess<SynchronizationPullResponse>) {

0 commit comments

Comments
 (0)