From 2146a718fb9a7f5df606beee08edf57b55e975a9 Mon Sep 17 00:00:00 2001 From: bponders12-cell Date: Tue, 1 Sep 2026 20:45:40 -0400 Subject: [PATCH] Harden sync retry and expose batch backup operation --- lib/services/sync/sync_manager.dart | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/services/sync/sync_manager.dart b/lib/services/sync/sync_manager.dart index 9f9bda0..2196920 100644 --- a/lib/services/sync/sync_manager.dart +++ b/lib/services/sync/sync_manager.dart @@ -63,7 +63,19 @@ class SyncManager extends ChangeNotifier { return item; } - /// Rearms only authentication-blocked work. Call this after a successful login/link. + /// Enqueues every local ride for the selected cloud provider. Existing + /// synced/queued items remain idempotent and are not duplicated. + Future backupAllRideIds(Iterable rideIds, {String? targetProviderId}) async { + var enqueued = 0; + for (final rideId in rideIds) { + await enqueueRide(rideId, targetProviderId: targetProviderId, autoProcess: false); + enqueued++; + } + if (enqueued > 0) unawaited(processQueue()); + return enqueued; + } + + /// Rearms authentication-blocked work. Call this after a successful login/link. Future retryAuthRequired() async { for (final item in _outbox.getAllItems().where((i) => i.status == SyncStatus.authRequired)) { await _outbox.update(item.copyWith(status: SyncStatus.queued, clearLastError: true, clearNextRetry: true)); @@ -88,7 +100,6 @@ class SyncManager extends ChangeNotifier { notifyListeners(); try { final now = _now(); - // Snapshot eligible items once; each item is durably marked before network I/O. final eligibleItems = _outbox.getEligibleItems(now); for (final item in eligibleItems) { final provider = _providers[item.providerId]; @@ -141,8 +152,11 @@ class SyncManager extends ChangeNotifier { } } + /// Re-arms retryable/pending work and terminal failures. Failed items are + /// intentionally retained until the retry is explicitly requested. Future retryAllPending() async { - for (final item in _outbox.getPendingItems()) { + final retryable = _outbox.getAllItems().where((i) => i.status.isPending || i.status == SyncStatus.failed).toList(growable: false); + for (final item in retryable) { await _outbox.update(item.copyWith(status: SyncStatus.queued, clearLastError: true, clearNextRetry: true)); } await processQueue();