feat: websocket background sync (#19888)

* feat: websocket background sync

* batch websocket

* pr feedback
This commit is contained in:
Alex 2025-07-15 09:38:28 -05:00 committed by GitHub
parent 0acbf1199a
commit 59e7754bdc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 116 additions and 1 deletions

View file

@ -6,6 +6,7 @@ import 'package:worker_manager/worker_manager.dart';
class BackgroundSyncManager {
Cancelable<void>? _syncTask;
Cancelable<void>? _syncWebsocketTask;
Cancelable<void>? _deviceAlbumSyncTask;
Cancelable<void>? _hashTask;
@ -20,6 +21,12 @@ class BackgroundSyncManager {
_syncTask?.cancel();
_syncTask = null;
if (_syncWebsocketTask != null) {
futures.add(_syncWebsocketTask!.future);
}
_syncWebsocketTask?.cancel();
_syncWebsocketTask = null;
return Future.wait(futures);
}
@ -72,4 +79,19 @@ class BackgroundSyncManager {
_syncTask = null;
});
}
Future<void> syncWebsocketBatch(List<dynamic> batchData) {
if (_syncWebsocketTask != null) {
return _syncWebsocketTask!.future;
}
_syncWebsocketTask = runInIsolateGentle(
computation: (ref) => ref
.read(syncStreamServiceProvider)
.handleWsAssetUploadReadyV1Batch(batchData),
);
return _syncWebsocketTask!.whenComplete(() {
_syncWebsocketTask = null;
});
}
}