mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
feat(mobile)!: batched full/initial sync (#4840)
* feat(mobile): batched full/initial sync * use OptionalBetween * skip/take as integer --------- Co-authored-by: Fynn Petersen-Frey <zoodyy@users.noreply.github.com> Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
parent
26fd9d7e5f
commit
21f2d3058a
10 changed files with 189 additions and 63 deletions
|
|
@ -197,7 +197,7 @@ class SyncService {
|
|||
User user,
|
||||
FutureOr<List<Asset>?> Function(User user) loadAssets,
|
||||
) async {
|
||||
final DateTime now = DateTime.now();
|
||||
final DateTime now = DateTime.now().toUtc();
|
||||
final List<Asset>? remote = await loadAssets(user);
|
||||
if (remote == null) {
|
||||
return false;
|
||||
|
|
@ -210,6 +210,10 @@ class SyncService {
|
|||
assert(inDb.isSorted(Asset.compareByChecksum), "inDb not sorted!");
|
||||
|
||||
remote.sort(Asset.compareByChecksum);
|
||||
|
||||
// filter our duplicates that might be introduced by the chunked retrieval
|
||||
remote.uniqueConsecutive(compare: Asset.compareByChecksum);
|
||||
|
||||
final (toAdd, toUpdate, toRemove) = _diffAssets(remote, inDb, remote: true);
|
||||
if (toAdd.isEmpty && toUpdate.isEmpty && toRemove.isEmpty) {
|
||||
await _updateUserAssetsETag(user, now);
|
||||
|
|
@ -759,6 +763,12 @@ class SyncService {
|
|||
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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue