chore: check before sync linked albums from websocket events (#21941)

This commit is contained in:
Alex 2025-09-14 02:08:41 -05:00 committed by GitHub
parent a122d4b969
commit 71e33e35dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 7 deletions

View file

@ -100,8 +100,14 @@ class BackgroundSyncManager {
// We use a ternary operator to avoid [_deviceAlbumSyncTask] from being // We use a ternary operator to avoid [_deviceAlbumSyncTask] from being
// captured by the closure passed to [runInIsolateGentle]. // captured by the closure passed to [runInIsolateGentle].
_deviceAlbumSyncTask = full _deviceAlbumSyncTask = full
? runInIsolateGentle(computation: (ref) => ref.read(localSyncServiceProvider).sync(full: true)) ? runInIsolateGentle(
: runInIsolateGentle(computation: (ref) => ref.read(localSyncServiceProvider).sync(full: false)); computation: (ref) => ref.read(localSyncServiceProvider).sync(full: true),
debugLabel: 'local-sync-full-true',
)
: runInIsolateGentle(
computation: (ref) => ref.read(localSyncServiceProvider).sync(full: false),
debugLabel: 'local-sync-full-false',
);
return _deviceAlbumSyncTask! return _deviceAlbumSyncTask!
.whenComplete(() { .whenComplete(() {
@ -122,7 +128,10 @@ class BackgroundSyncManager {
onHashingStart?.call(); onHashingStart?.call();
_hashTask = runInIsolateGentle(computation: (ref) => ref.read(hashServiceProvider).hashAssets()); _hashTask = runInIsolateGentle(
computation: (ref) => ref.read(hashServiceProvider).hashAssets(),
debugLabel: 'hash-assets',
);
return _hashTask! return _hashTask!
.whenComplete(() { .whenComplete(() {
@ -142,7 +151,10 @@ class BackgroundSyncManager {
onRemoteSyncStart?.call(); onRemoteSyncStart?.call();
_syncTask = runInIsolateGentle(computation: (ref) => ref.read(syncStreamServiceProvider).sync()); _syncTask = runInIsolateGentle(
computation: (ref) => ref.read(syncStreamServiceProvider).sync(),
debugLabel: 'remote-sync',
);
return _syncTask! return _syncTask!
.whenComplete(() { .whenComplete(() {
onRemoteSyncComplete?.call(); onRemoteSyncComplete?.call();
@ -169,7 +181,7 @@ class BackgroundSyncManager {
return _linkedAlbumSyncTask!.future; return _linkedAlbumSyncTask!.future;
} }
_linkedAlbumSyncTask = runInIsolateGentle(computation: syncLinkedAlbumsIsolated); _linkedAlbumSyncTask = runInIsolateGentle(computation: syncLinkedAlbumsIsolated, debugLabel: 'linked-album-sync');
return _linkedAlbumSyncTask!.whenComplete(() { return _linkedAlbumSyncTask!.whenComplete(() {
_linkedAlbumSyncTask = null; _linkedAlbumSyncTask = null;
}); });
@ -178,4 +190,5 @@ class BackgroundSyncManager {
Cancelable<void> _handleWsAssetUploadReadyV1Batch(List<dynamic> batchData) => runInIsolateGentle( Cancelable<void> _handleWsAssetUploadReadyV1Batch(List<dynamic> batchData) => runInIsolateGentle(
computation: (ref) => ref.read(syncStreamServiceProvider).handleWsAssetUploadReadyV1Batch(batchData), computation: (ref) => ref.read(syncStreamServiceProvider).handleWsAssetUploadReadyV1Batch(batchData),
debugLabel: 'websocket-batch',
); );

View file

@ -320,10 +320,13 @@ class WebsocketNotifier extends StateNotifier<WebsocketState> {
return; return;
} }
final isSyncAlbumEnabled = Store.get(StoreKey.syncAlbums, false);
try { try {
unawaited( unawaited(
_ref.read(backgroundSyncProvider).syncWebsocketBatch(_batchedAssetUploadReady.toList()).then((_) { _ref.read(backgroundSyncProvider).syncWebsocketBatch(_batchedAssetUploadReady.toList()).then((_) {
return _ref.read(backgroundSyncProvider).syncLinkedAlbum(); if (isSyncAlbumEnabled) {
_ref.read(backgroundSyncProvider).syncLinkedAlbum();
}
}), }),
); );
} catch (error) { } catch (error) {

View file

@ -84,7 +84,7 @@ Cancelable<T?> runInIsolateGentle<T>({
return null; return null;
}, },
(error, stack) { (error, stack) {
dPrint(() => "Error in isolate zone: $error, $stack"); dPrint(() => "Error in isolate $debugLabel zone: $error, $stack");
}, },
); );
return null; return null;