Skip to content

Commit 71e33e3

Browse files
authored
chore: check before sync linked albums from websocket events (#21941)
1 parent a122d4b commit 71e33e3

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

mobile/lib/domain/utils/background_sync.dart

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,14 @@ class BackgroundSyncManager {
100100
// We use a ternary operator to avoid [_deviceAlbumSyncTask] from being
101101
// captured by the closure passed to [runInIsolateGentle].
102102
_deviceAlbumSyncTask = full
103-
? runInIsolateGentle(computation: (ref) => ref.read(localSyncServiceProvider).sync(full: true))
104-
: runInIsolateGentle(computation: (ref) => ref.read(localSyncServiceProvider).sync(full: false));
103+
? runInIsolateGentle(
104+
computation: (ref) => ref.read(localSyncServiceProvider).sync(full: true),
105+
debugLabel: 'local-sync-full-true',
106+
)
107+
: runInIsolateGentle(
108+
computation: (ref) => ref.read(localSyncServiceProvider).sync(full: false),
109+
debugLabel: 'local-sync-full-false',
110+
);
105111

106112
return _deviceAlbumSyncTask!
107113
.whenComplete(() {
@@ -122,7 +128,10 @@ class BackgroundSyncManager {
122128

123129
onHashingStart?.call();
124130

125-
_hashTask = runInIsolateGentle(computation: (ref) => ref.read(hashServiceProvider).hashAssets());
131+
_hashTask = runInIsolateGentle(
132+
computation: (ref) => ref.read(hashServiceProvider).hashAssets(),
133+
debugLabel: 'hash-assets',
134+
);
126135

127136
return _hashTask!
128137
.whenComplete(() {
@@ -142,7 +151,10 @@ class BackgroundSyncManager {
142151

143152
onRemoteSyncStart?.call();
144153

145-
_syncTask = runInIsolateGentle(computation: (ref) => ref.read(syncStreamServiceProvider).sync());
154+
_syncTask = runInIsolateGentle(
155+
computation: (ref) => ref.read(syncStreamServiceProvider).sync(),
156+
debugLabel: 'remote-sync',
157+
);
146158
return _syncTask!
147159
.whenComplete(() {
148160
onRemoteSyncComplete?.call();
@@ -169,7 +181,7 @@ class BackgroundSyncManager {
169181
return _linkedAlbumSyncTask!.future;
170182
}
171183

172-
_linkedAlbumSyncTask = runInIsolateGentle(computation: syncLinkedAlbumsIsolated);
184+
_linkedAlbumSyncTask = runInIsolateGentle(computation: syncLinkedAlbumsIsolated, debugLabel: 'linked-album-sync');
173185
return _linkedAlbumSyncTask!.whenComplete(() {
174186
_linkedAlbumSyncTask = null;
175187
});
@@ -178,4 +190,5 @@ class BackgroundSyncManager {
178190

179191
Cancelable<void> _handleWsAssetUploadReadyV1Batch(List<dynamic> batchData) => runInIsolateGentle(
180192
computation: (ref) => ref.read(syncStreamServiceProvider).handleWsAssetUploadReadyV1Batch(batchData),
193+
debugLabel: 'websocket-batch',
181194
);

mobile/lib/providers/websocket.provider.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,13 @@ class WebsocketNotifier extends StateNotifier<WebsocketState> {
320320
return;
321321
}
322322

323+
final isSyncAlbumEnabled = Store.get(StoreKey.syncAlbums, false);
323324
try {
324325
unawaited(
325326
_ref.read(backgroundSyncProvider).syncWebsocketBatch(_batchedAssetUploadReady.toList()).then((_) {
326-
return _ref.read(backgroundSyncProvider).syncLinkedAlbum();
327+
if (isSyncAlbumEnabled) {
328+
_ref.read(backgroundSyncProvider).syncLinkedAlbum();
329+
}
327330
}),
328331
);
329332
} catch (error) {

mobile/lib/utils/isolate.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Cancelable<T?> runInIsolateGentle<T>({
8484
return null;
8585
},
8686
(error, stack) {
87-
dPrint(() => "Error in isolate zone: $error, $stack");
87+
dPrint(() => "Error in isolate $debugLabel zone: $error, $stack");
8888
},
8989
);
9090
return null;

0 commit comments

Comments
 (0)