瀏覽代碼

fix(mobile): update local deleted assets in sync (#5099)

Fynn Petersen-Frey 1 年之前
父節點
當前提交
63a745c7ad
共有 1 個文件被更改,包括 11 次插入6 次删除
  1. 11 6
      mobile/lib/shared/services/sync.service.dart

+ 11 - 6
mobile/lib/shared/services/sync.service.dart

@@ -785,15 +785,20 @@ class SyncService {
   bool? remote,
   int Function(Asset, Asset) compare = Asset.compareByChecksum,
 }) {
+  // fast paths for trivial cases: reduces memory usage during initial sync etc.
+  if (assets.isEmpty && inDb.isEmpty) {
+    return const ([], [], []);
+  } else if (assets.isEmpty && remote == null) {
+    // remove all from database
+    return (const [], const [], inDb);
+  } else if (inDb.isEmpty) {
+    // add all assets
+    return (assets, const [], const []);
+  }
+
   final List<Asset> toAdd = [];
   final List<Asset> toUpdate = [];
   final List<Asset> toRemove = [];
-  if (assets.isEmpty || inDb.isEmpty) {
-    // fast path for trivial cases: halfes memory usage during initial sync
-    return assets.isEmpty
-        ? (toAdd, toUpdate, inDb) // remove all from DB
-        : (assets, toUpdate, toRemove); // add all assets
-  }
   diffSortedListsSync(
     inDb,
     assets,