mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
group local assets by checksum before moving to trash
delete LocalAssetEntity records when moved to trash refactor code
This commit is contained in:
parent
c7e4f9db85
commit
d8fb41e795
2 changed files with 16 additions and 8 deletions
|
|
@ -35,8 +35,8 @@ class TrashSyncService {
|
||||||
if (!_platform.isAndroid || !_appSettingsService.getSetting<bool>(AppSettingsEnum.manageLocalMediaAndroid)) {
|
if (!_platform.isAndroid || !_appSettingsService.getSetting<bool>(AppSettingsEnum.manageLocalMediaAndroid)) {
|
||||||
return Future.value();
|
return Future.value();
|
||||||
}
|
}
|
||||||
final trashedAssetsChecksums = <String>[];
|
final trashedAssetsChecksums = <String>{};
|
||||||
final modifiedAssetsChecksums = <String>[];
|
final modifiedAssetsChecksums = <String>{};
|
||||||
for (var syncItem in syncItems) {
|
for (var syncItem in syncItems) {
|
||||||
if (syncItem.deletedAt != null) {
|
if (syncItem.deletedAt != null) {
|
||||||
trashedAssetsChecksums.add(syncItem.checksum);
|
trashedAssetsChecksums.add(syncItem.checksum);
|
||||||
|
|
@ -52,15 +52,20 @@ class TrashSyncService {
|
||||||
if (trashedAssetsChecksums.isEmpty) {
|
if (trashedAssetsChecksums.isEmpty) {
|
||||||
return Future.value();
|
return Future.value();
|
||||||
} else {
|
} else {
|
||||||
final localAssetsToTrash = await _localAssetRepository.getByChecksums(trashedAssetsChecksums);
|
final candidatesToTrash = await _localAssetRepository.getByChecksums(trashedAssetsChecksums);
|
||||||
if (localAssetsToTrash.isNotEmpty) {
|
if (candidatesToTrash.isNotEmpty) {
|
||||||
|
final groupedByChecksum = <String, LocalAsset>{};
|
||||||
|
for (final localAsset in candidatesToTrash) {
|
||||||
|
groupedByChecksum[localAsset.checksum!] = localAsset;
|
||||||
|
}
|
||||||
final mediaUrls = await Future.wait(
|
final mediaUrls = await Future.wait(
|
||||||
localAssetsToTrash.map(
|
groupedByChecksum.values.map(
|
||||||
(localAsset) => _storageRepository.getAssetEntityForAsset(localAsset).then((e) => e?.getMediaUrl()),
|
(localAsset) => _storageRepository.getAssetEntityForAsset(localAsset).then((e) => e?.getMediaUrl()),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
_logger.info("Moving to trash ${mediaUrls.join(", ")} assets");
|
_logger.info("Moving to trash ${mediaUrls.join(", ")} assets");
|
||||||
await _localFilesManager.moveToTrash(mediaUrls.nonNulls.toList());
|
await _localFilesManager.moveToTrash(mediaUrls.nonNulls.toList());
|
||||||
|
await _localAssetRepository.delete(candidatesToTrash.map((asset) => asset.id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ class DriftLocalAssetRepository extends DriftDatabaseRepository {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> delete(List<String> ids) {
|
Future<void> delete(Iterable<String> ids) {
|
||||||
if (ids.isEmpty) {
|
if (ids.isEmpty) {
|
||||||
return Future.value();
|
return Future.value();
|
||||||
}
|
}
|
||||||
|
|
@ -71,8 +71,11 @@ class DriftLocalAssetRepository extends DriftDatabaseRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<LocalAsset>> getByChecksums(Iterable<String> checksums) {
|
Future<List<LocalAsset>> getByChecksums(Iterable<String> checksums) {
|
||||||
if (checksums.isEmpty) return Future.value([]);
|
if (checksums.isEmpty) {
|
||||||
final query = _db.localAssetEntity.select()..where((lae) => lae.checksum.isIn(checksums));
|
return Future.value([]);
|
||||||
|
}
|
||||||
|
final query = _db.localAssetEntity.select()
|
||||||
|
..where((lae) => lae.checksum.isIn(checksums));
|
||||||
return query.map((row) => row.toDto()).get();
|
return query.map((row) => row.toDto()).get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue