mirror of
https://github.com/immich-app/immich
synced 2026-08-15 13:03:57 +00:00
fix(mobile): run one more sync round when a request arrives mid sync (#30478)
* fix(mobile): run one more sync round when a request arrives mid sync * fix(mobile): only queue the extra sync round when the caller asks for it * fix(mobile): skip the queued sync round when the sync fails * clear the sync task in whenComplete and gate the queued round on the result * simplify the queued flag gate
This commit is contained in:
parent
79d485c759
commit
7121e0a75c
2 changed files with 11 additions and 3 deletions
|
|
@ -28,6 +28,7 @@ class BackgroundSyncManager {
|
||||||
final SyncErrorCallback? onCloudIdSyncError;
|
final SyncErrorCallback? onCloudIdSyncError;
|
||||||
|
|
||||||
Cancelable<bool?>? _syncTask;
|
Cancelable<bool?>? _syncTask;
|
||||||
|
bool _syncQueued = false;
|
||||||
Cancelable<void>? _syncWebsocketTask;
|
Cancelable<void>? _syncWebsocketTask;
|
||||||
Cancelable<void>? _cloudIdSyncTask;
|
Cancelable<void>? _cloudIdSyncTask;
|
||||||
Cancelable<void>? _deviceAlbumSyncTask;
|
Cancelable<void>? _deviceAlbumSyncTask;
|
||||||
|
|
@ -50,6 +51,7 @@ class BackgroundSyncManager {
|
||||||
});
|
});
|
||||||
|
|
||||||
Future<void> cancel() async {
|
Future<void> cancel() async {
|
||||||
|
_syncQueued = false;
|
||||||
final tasks = [
|
final tasks = [
|
||||||
_syncTask,
|
_syncTask,
|
||||||
_syncWebsocketTask,
|
_syncWebsocketTask,
|
||||||
|
|
@ -133,8 +135,9 @@ class BackgroundSyncManager {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> syncRemote() {
|
Future<bool> syncRemote({bool enqueue = false}) {
|
||||||
if (_syncTask != null) {
|
if (_syncTask != null) {
|
||||||
|
_syncQueued |= enqueue;
|
||||||
return _syncTask!.future.then((result) => result ?? false).catchError((_) => false);
|
return _syncTask!.future.then((result) => result ?? false).catchError((_) => false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -148,15 +151,20 @@ class BackgroundSyncManager {
|
||||||
.then((result) {
|
.then((result) {
|
||||||
final success = result ?? false;
|
final success = result ?? false;
|
||||||
onRemoteSyncComplete?.call(success);
|
onRemoteSyncComplete?.call(success);
|
||||||
|
_syncQueued &= success;
|
||||||
return success;
|
return success;
|
||||||
})
|
})
|
||||||
.catchError((error) {
|
.catchError((error) {
|
||||||
onRemoteSyncError?.call(error.toString());
|
onRemoteSyncError?.call(error.toString());
|
||||||
_syncTask = null;
|
_syncQueued = false;
|
||||||
return false;
|
return false;
|
||||||
})
|
})
|
||||||
.whenComplete(() {
|
.whenComplete(() {
|
||||||
_syncTask = null;
|
_syncTask = null;
|
||||||
|
if (_syncQueued) {
|
||||||
|
_syncQueued = false;
|
||||||
|
unawaited(syncRemote());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,7 @@ class WebsocketNotifier extends StateNotifier<WebsocketState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleRemoteChange(dynamic _) {
|
void _handleRemoteChange(dynamic _) {
|
||||||
unawaited(_ref.read(backgroundSyncProvider).syncRemote());
|
unawaited(_ref.read(backgroundSyncProvider).syncRemote(enqueue: true));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleSyncAssetEditReadyV2(dynamic data) {
|
void _handleSyncAssetEditReadyV2(dynamic data) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue