High performance self-hosted photo and video management solution.
TypeScript backup-toolfluttergoogle-photosgoogle-photos-alternativejavascriptmobile-appnestjsnodejsphoto-galleryphotosphotos-managementself-hostedsveltesveltekittypescriptvideos
fix(mobile): run one more sync round when a request arrives mid sync (#30478)
Santo Shakil7121e0a75ca5
diff --git a/mobile/lib/domain/utils/background_sync.dart b/mobile/lib/domain/utils/background_sync.dartindex 82f397d9b6..db0d93c92f 100644--- a/mobile/lib/domain/utils/background_sync.dart+++ b/mobile/lib/domain/utils/background_sync.dart@@ -28,6 +28,7 @@ class BackgroundSyncManager {final SyncErrorCallback? onCloudIdSyncError;Cancelable<bool?>? _syncTask;+ bool _syncQueued = false;Cancelable<void>? _syncWebsocketTask;Cancelable<void>? _cloudIdSyncTask;Cancelable<void>? _deviceAlbumSyncTask;@@ -50,6 +51,7 @@ class BackgroundSyncManager {});Future<void> cancel() async {+ _syncQueued = false;final tasks = [_syncTask,_syncWebsocketTask,@@ -133,8 +135,9 @@ class BackgroundSyncManager {});}- Future<bool> syncRemote() {+ Future<bool> syncRemote({bool enqueue = false}) {if (_syncTask != null) {+ _syncQueued |= enqueue;return _syncTask!.future.then((result) => result ?? false).catchError((_) => false);}@@ -148,15 +151,20 @@ class BackgroundSyncManager {.then((result) {final success = result ?? false;onRemoteSyncComplete?.call(success);+ _syncQueued &= success;return success;}).catchError((error) {onRemoteSyncError?.call(error.toString());- _syncTask = null;+ _syncQueued = false;return false;}).whenComplete(() {_syncTask = null;+ if (_syncQueued) {+ _syncQueued = false;+ unawaited(syncRemote());+ }});}diff --git a/mobile/lib/providers/websocket.provider.dart b/mobile/lib/providers/websocket.provider.dartindex c6ed09360a..05d1f3aac1 100644--- a/mobile/lib/providers/websocket.provider.dart+++ b/mobile/lib/providers/websocket.provider.dart@@ -187,7 +187,7 @@ class WebsocketNotifier extends StateNotifier<WebsocketState> {}void _handleRemoteChange(dynamic _) {- unawaited(_ref.read(backgroundSyncProvider).syncRemote());+ unawaited(_ref.read(backgroundSyncProvider).syncRemote(enqueue: true));}void _handleSyncAssetEditReadyV2(dynamic data) {