From 63a745c7adc513bb6b0ce3486a43e6db4898d0b9 Mon Sep 17 00:00:00 2001 From: Fynn Petersen-Frey <10599762+fyfrey@users.noreply.github.com> Date: Fri, 17 Nov 2023 22:35:57 +0100 Subject: [PATCH] fix(mobile): update local deleted assets in sync (#5099) --- mobile/lib/shared/services/sync.service.dart | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/mobile/lib/shared/services/sync.service.dart b/mobile/lib/shared/services/sync.service.dart index 50b96319db..08025ed710 100644 --- a/mobile/lib/shared/services/sync.service.dart +++ b/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 toAdd = []; final List toUpdate = []; final List 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,