Skip to content

Commit 100a1e7

Browse files
misc fixes
1 parent b72a91a commit 100a1e7

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

mobile/lib/domain/services/sync_stream.service.dart

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ import 'package:logging/logging.dart';
99
import 'package:openapi/api.dart';
1010
import 'package:worker_manager/worker_manager.dart';
1111

12+
const _kSyncTypeOrder = [
13+
SyncEntityType.userV1,
14+
SyncEntityType.partnerV1,
15+
SyncEntityType.assetV1,
16+
SyncEntityType.assetExifV1,
17+
SyncEntityType.partnerAssetV1,
18+
SyncEntityType.partnerAssetExifV1,
19+
];
20+
1221
class SyncStreamService {
1322
final Logger _logger = Logger('SyncStreamService');
1423

@@ -102,7 +111,12 @@ class SyncStreamService {
102111
final eventsMap = events.groupListsBy((event) => event.type);
103112
final Map<SyncEntityType, String> acks = {};
104113

105-
for (final entry in eventsMap.entries) {
114+
for (final type in _kSyncTypeOrder) {
115+
final data = eventsMap[type];
116+
if (data == null) {
117+
continue;
118+
}
119+
106120
if (_cancelChecker?.call() ?? false) {
107121
_logger.info("Sync cancelled, stopping stream");
108122
mutex?.complete();
@@ -117,9 +131,6 @@ class SyncStreamService {
117131
return;
118132
}
119133

120-
final type = entry.key;
121-
final data = entry.value;
122-
123134
if (data.isEmpty) {
124135
_logger.warning("Received empty sync events for $type");
125136
continue;

mobile/lib/domain/utils/background_sync.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ class BackgroundSyncManager {
1111

1212
BackgroundSyncManager();
1313

14-
void cancel() {
14+
Future<void> cancel() {
15+
final futures = <Future>[];
16+
if (_userSyncTask != null) {
17+
futures.add(_userSyncTask!.future);
18+
}
1519
_userSyncTask?.cancel();
1620
_userSyncTask = null;
21+
return Future.wait(futures);
1722
}
1823

1924
Future<void> syncUsers() async {

mobile/lib/services/auth.service.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,10 @@ class AuthService {
120120
/// - Asset ETag
121121
///
122122
/// All deletions are executed in parallel using [Future.wait].
123-
Future<void> clearLocalData() {
124-
_backgroundSyncManager.cancel();
125-
return Future.wait([
123+
Future<void> clearLocalData() async {
124+
// Cancel any ongoing background sync operations before clearing data
125+
await _backgroundSyncManager.cancel();
126+
await Future.wait([
126127
_authRepository.clearLocalData(),
127128
Store.delete(StoreKey.currentUser),
128129
Store.delete(StoreKey.accessToken),

0 commit comments

Comments
 (0)