mirror of
https://github.com/immich-app/immich.git
synced 2025-10-24 23:39:03 -04:00
map cloud Ids during local sync
This commit is contained in:
parent
61e079a63e
commit
bfadf68e15
@ -44,8 +44,9 @@ class LocalSyncService {
|
|||||||
|
|
||||||
final deviceAlbums = await _nativeSyncApi.getAlbums();
|
final deviceAlbums = await _nativeSyncApi.getAlbums();
|
||||||
await _localAlbumRepository.updateAll(deviceAlbums.toLocalAlbums());
|
await _localAlbumRepository.updateAll(deviceAlbums.toLocalAlbums());
|
||||||
|
final newAssets = delta.updates.toLocalAssets();
|
||||||
await _localAlbumRepository.processDelta(
|
await _localAlbumRepository.processDelta(
|
||||||
updates: delta.updates.toLocalAssets(),
|
updates: newAssets,
|
||||||
deletes: delta.deletes,
|
deletes: delta.deletes,
|
||||||
assetAlbums: delta.assetAlbums,
|
assetAlbums: delta.assetAlbums,
|
||||||
);
|
);
|
||||||
@ -74,11 +75,7 @@ class LocalSyncService {
|
|||||||
await updateAlbum(dbAlbum, album);
|
await updateAlbum(dbAlbum, album);
|
||||||
}
|
}
|
||||||
|
|
||||||
final newAssetIds = delta.updates.map((e) => e.id).toList();
|
await _mapIosCloudIds(newAssets);
|
||||||
if (newAssetIds.isNotEmpty) {
|
|
||||||
final cloudMapping = await _nativeSyncApi.getCloudIdForAssetIds(newAssetIds);
|
|
||||||
await _localAlbumRepository.updateCloudMapping(cloudMapping);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await _nativeSyncApi.checkpointSync();
|
await _nativeSyncApi.checkpointSync();
|
||||||
@ -118,9 +115,12 @@ class LocalSyncService {
|
|||||||
try {
|
try {
|
||||||
_log.fine("Adding device album ${album.name}");
|
_log.fine("Adding device album ${album.name}");
|
||||||
|
|
||||||
final assets = album.assetCount > 0 ? await _nativeSyncApi.getAssetsForAlbum(album.id) : <PlatformAsset>[];
|
final assets = album.assetCount > 0
|
||||||
|
? await _nativeSyncApi.getAssetsForAlbum(album.id).then((a) => a.toLocalAssets())
|
||||||
|
: <LocalAsset>[];
|
||||||
|
|
||||||
await _localAlbumRepository.upsert(album, toUpsert: assets.toLocalAssets());
|
await _localAlbumRepository.upsert(album, toUpsert: assets);
|
||||||
|
await _mapIosCloudIds(assets);
|
||||||
_log.fine("Successfully added device album ${album.name}");
|
_log.fine("Successfully added device album ${album.name}");
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
_log.warning("Error while adding device album", e, s);
|
_log.warning("Error while adding device album", e, s);
|
||||||
@ -190,13 +190,16 @@ class LocalSyncService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final newAssets = await _nativeSyncApi.getAssetsForAlbum(deviceAlbum.id, updatedTimeCond: updatedTime);
|
final newAssets = await _nativeSyncApi
|
||||||
|
.getAssetsForAlbum(deviceAlbum.id, updatedTimeCond: updatedTime)
|
||||||
|
.then((a) => a.toLocalAssets());
|
||||||
|
|
||||||
await _localAlbumRepository.upsert(
|
await _localAlbumRepository.upsert(
|
||||||
deviceAlbum.copyWith(backupSelection: dbAlbum.backupSelection),
|
deviceAlbum.copyWith(backupSelection: dbAlbum.backupSelection),
|
||||||
toUpsert: newAssets.toLocalAssets(),
|
toUpsert: newAssets,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await _mapIosCloudIds(newAssets);
|
||||||
return true;
|
return true;
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
_log.warning("Error on fast syncing local album: ${dbAlbum.name}", e, s);
|
_log.warning("Error on fast syncing local album: ${dbAlbum.name}", e, s);
|
||||||
@ -228,6 +231,7 @@ class LocalSyncService {
|
|||||||
if (dbAlbum.assetCount == 0) {
|
if (dbAlbum.assetCount == 0) {
|
||||||
_log.fine("Device album ${deviceAlbum.name} is empty. Adding assets to DB.");
|
_log.fine("Device album ${deviceAlbum.name} is empty. Adding assets to DB.");
|
||||||
await _localAlbumRepository.upsert(updatedDeviceAlbum, toUpsert: assetsInDevice);
|
await _localAlbumRepository.upsert(updatedDeviceAlbum, toUpsert: assetsInDevice);
|
||||||
|
await _mapIosCloudIds(assetsInDevice);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,6 +269,7 @@ class LocalSyncService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await _localAlbumRepository.upsert(updatedDeviceAlbum, toUpsert: assetsToUpsert, toDelete: assetsToDelete);
|
await _localAlbumRepository.upsert(updatedDeviceAlbum, toUpsert: assetsToUpsert, toDelete: assetsToDelete);
|
||||||
|
await _mapIosCloudIds(assetsToUpsert);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
@ -273,6 +278,16 @@ class LocalSyncService {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _mapIosCloudIds(List<LocalAsset> assets) async {
|
||||||
|
if (!_platform.isIOS || assets.isEmpty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final assetIds = assets.map((a) => a.id).toList();
|
||||||
|
final cloudMapping = await _nativeSyncApi.getCloudIdForAssetIds(assetIds);
|
||||||
|
await _localAlbumRepository.updateCloudMapping(cloudMapping);
|
||||||
|
}
|
||||||
|
|
||||||
bool _assetsEqual(LocalAsset a, LocalAsset b) {
|
bool _assetsEqual(LocalAsset a, LocalAsset b) {
|
||||||
return a.updatedAt.isAtSameMomentAs(b.updatedAt) &&
|
return a.updatedAt.isAtSameMomentAs(b.updatedAt) &&
|
||||||
a.createdAt.isAtSameMomentAs(b.createdAt) &&
|
a.createdAt.isAtSameMomentAs(b.createdAt) &&
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user