mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
optimize sync trashed assets call in full sync mode
refactor code
This commit is contained in:
parent
4d88ffe694
commit
c67a147110
2 changed files with 15 additions and 10 deletions
|
|
@ -96,6 +96,10 @@ class LocalSyncService {
|
|||
try {
|
||||
final Stopwatch stopwatch = Stopwatch()..start();
|
||||
|
||||
if (CurrentPlatform.isAndroid) {
|
||||
await _syncTrashedAssets(sinceLastCheckpoint: false);
|
||||
}
|
||||
|
||||
final deviceAlbums = await _nativeSyncApi.getAlbums();
|
||||
final dbAlbums = await _localAlbumRepository.getAll(sortBy: {SortLocalAlbumsBy.id});
|
||||
|
||||
|
|
@ -107,9 +111,6 @@ class LocalSyncService {
|
|||
onlyFirst: removeAlbum,
|
||||
onlySecond: addAlbum,
|
||||
);
|
||||
if (CurrentPlatform.isAndroid) {
|
||||
await _syncTrashedAssets(sinceLastCheckpoint: false);
|
||||
}
|
||||
|
||||
await _nativeSyncApi.checkpointSync();
|
||||
stopwatch.stop();
|
||||
|
|
@ -309,11 +310,7 @@ class LocalSyncService {
|
|||
);
|
||||
|
||||
_log.fine("syncTrashedAssets, trashedAssets: ${trashedAssets.map((e) => e.asset.id)}");
|
||||
if (sinceLastCheckpoint) {
|
||||
await _trashedLocalAssetRepository.applyDelta(trashedAssets);
|
||||
} else {
|
||||
await _trashedLocalAssetRepository.applySnapshot(trashedAssets);
|
||||
}
|
||||
await _trashedLocalAssetRepository.applyTrashedAssets(trashedAssets, sinceLastCheckpoint);
|
||||
|
||||
final remoteAssetsToRestore = await _trashedLocalAssetRepository.getToRestore();
|
||||
if (remoteAssetsToRestore.isNotEmpty) {
|
||||
|
|
|
|||
|
|
@ -56,10 +56,18 @@ class DriftTrashedLocalAssetRepository extends DriftDatabaseRepository {
|
|||
return rows.map((result) => result.readTable(_db.trashedLocalAssetEntity).toLocalAsset());
|
||||
}
|
||||
|
||||
Future<void> applyTrashedAssets(Iterable<TrashedAsset> trashedAssets, bool asDelta) async {
|
||||
if (asDelta){
|
||||
return _applyDelta(trashedAssets);
|
||||
} else {
|
||||
return _applySnapshot(trashedAssets);
|
||||
}
|
||||
}
|
||||
|
||||
/// Applies resulted snapshot of trashed assets:
|
||||
/// - upserts incoming rows
|
||||
/// - deletes rows that are not present in the snapshot
|
||||
Future<void> applySnapshot(Iterable<TrashedAsset> trashedAssets) async {
|
||||
Future<void> _applySnapshot(Iterable<TrashedAsset> trashedAssets) async {
|
||||
if (trashedAssets.isEmpty) {
|
||||
await _db.delete(_db.trashedLocalAssetEntity).go();
|
||||
return;
|
||||
|
|
@ -110,7 +118,7 @@ class DriftTrashedLocalAssetRepository extends DriftDatabaseRepository {
|
|||
});
|
||||
}
|
||||
|
||||
Future<void> applyDelta(Iterable<TrashedAsset> trashedAssets) async {
|
||||
Future<void> _applyDelta(Iterable<TrashedAsset> trashedAssets) async {
|
||||
if (trashedAssets.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue