Skip to content

Commit

Permalink
fix(mobile): update local deleted assets in sync (#5099)
Browse files Browse the repository at this point in the history
  • Loading branch information
fyfrey authored Nov 17, 2023
1 parent 47a4984 commit 63a745c
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions mobile/lib/shared/services/sync.service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 63a745c

Please sign in to comment.