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 {
|
try {
|
||||||
final Stopwatch stopwatch = Stopwatch()..start();
|
final Stopwatch stopwatch = Stopwatch()..start();
|
||||||
|
|
||||||
|
if (CurrentPlatform.isAndroid) {
|
||||||
|
await _syncTrashedAssets(sinceLastCheckpoint: false);
|
||||||
|
}
|
||||||
|
|
||||||
final deviceAlbums = await _nativeSyncApi.getAlbums();
|
final deviceAlbums = await _nativeSyncApi.getAlbums();
|
||||||
final dbAlbums = await _localAlbumRepository.getAll(sortBy: {SortLocalAlbumsBy.id});
|
final dbAlbums = await _localAlbumRepository.getAll(sortBy: {SortLocalAlbumsBy.id});
|
||||||
|
|
||||||
|
|
@ -107,9 +111,6 @@ class LocalSyncService {
|
||||||
onlyFirst: removeAlbum,
|
onlyFirst: removeAlbum,
|
||||||
onlySecond: addAlbum,
|
onlySecond: addAlbum,
|
||||||
);
|
);
|
||||||
if (CurrentPlatform.isAndroid) {
|
|
||||||
await _syncTrashedAssets(sinceLastCheckpoint: false);
|
|
||||||
}
|
|
||||||
|
|
||||||
await _nativeSyncApi.checkpointSync();
|
await _nativeSyncApi.checkpointSync();
|
||||||
stopwatch.stop();
|
stopwatch.stop();
|
||||||
|
|
@ -309,11 +310,7 @@ class LocalSyncService {
|
||||||
);
|
);
|
||||||
|
|
||||||
_log.fine("syncTrashedAssets, trashedAssets: ${trashedAssets.map((e) => e.asset.id)}");
|
_log.fine("syncTrashedAssets, trashedAssets: ${trashedAssets.map((e) => e.asset.id)}");
|
||||||
if (sinceLastCheckpoint) {
|
await _trashedLocalAssetRepository.applyTrashedAssets(trashedAssets, sinceLastCheckpoint);
|
||||||
await _trashedLocalAssetRepository.applyDelta(trashedAssets);
|
|
||||||
} else {
|
|
||||||
await _trashedLocalAssetRepository.applySnapshot(trashedAssets);
|
|
||||||
}
|
|
||||||
|
|
||||||
final remoteAssetsToRestore = await _trashedLocalAssetRepository.getToRestore();
|
final remoteAssetsToRestore = await _trashedLocalAssetRepository.getToRestore();
|
||||||
if (remoteAssetsToRestore.isNotEmpty) {
|
if (remoteAssetsToRestore.isNotEmpty) {
|
||||||
|
|
|
||||||
|
|
@ -56,10 +56,18 @@ class DriftTrashedLocalAssetRepository extends DriftDatabaseRepository {
|
||||||
return rows.map((result) => result.readTable(_db.trashedLocalAssetEntity).toLocalAsset());
|
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:
|
/// Applies resulted snapshot of trashed assets:
|
||||||
/// - upserts incoming rows
|
/// - upserts incoming rows
|
||||||
/// - deletes rows that are not present in the snapshot
|
/// - 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) {
|
if (trashedAssets.isEmpty) {
|
||||||
await _db.delete(_db.trashedLocalAssetEntity).go();
|
await _db.delete(_db.trashedLocalAssetEntity).go();
|
||||||
return;
|
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) {
|
if (trashedAssets.isEmpty) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue