mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
refactor code
remove unused model
This commit is contained in:
parent
4b2b99942c
commit
cdfa7ccbff
5 changed files with 20 additions and 61 deletions
|
|
@ -296,14 +296,7 @@ class BackgroundServicePlugin : FlutterPlugin, MethodChannel.MethodCallHandler,
|
|||
contentResolver.query(queryUri, projection, queryArgs, null)?.use { cursor ->
|
||||
if (cursor.moveToFirst()) {
|
||||
val id = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns._ID))
|
||||
// same order as AssetType from dart
|
||||
val contentUri = when (type) {
|
||||
1 -> MediaStore.Images.Media.EXTERNAL_CONTENT_URI
|
||||
2 -> MediaStore.Video.Media.EXTERNAL_CONTENT_URI
|
||||
3 -> MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
|
||||
else -> queryUri
|
||||
}
|
||||
return ContentUris.withAppendedId(contentUri, id)
|
||||
return ContentUris.withAppendedId(contentUriForType(type), id)
|
||||
}
|
||||
}
|
||||
return null
|
||||
|
|
|
|||
|
|
@ -1,37 +0,0 @@
|
|||
class LocalTrashedAsset {
|
||||
final String localId;
|
||||
final String remoteId;
|
||||
final DateTime createdAt;
|
||||
|
||||
const LocalTrashedAsset({required this.localId, required this.remoteId, required this.createdAt});
|
||||
|
||||
LocalTrashedAsset copyWith({String? localId, String? remoteId, DateTime? createdAt}) {
|
||||
return LocalTrashedAsset(
|
||||
localId: localId ?? this.localId,
|
||||
remoteId: remoteId ?? this.remoteId,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (other is! LocalTrashedAsset) return false;
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other.localId == localId && other.remoteId == remoteId && other.createdAt == createdAt;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return localId.hashCode ^ remoteId.hashCode ^ createdAt.hashCode;
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '''LocalTrashedAsset: {
|
||||
localId: $localId,
|
||||
remoteId: $remoteId,
|
||||
createdAt: $createdAt
|
||||
}''';
|
||||
}
|
||||
}
|
||||
|
|
@ -65,14 +65,17 @@ class HashService {
|
|||
|
||||
if (_trashSyncService.isAutoSyncMode) {
|
||||
final backupAlbums = await _localAlbumRepository.getBackupAlbums();
|
||||
for (final album in backupAlbums) {
|
||||
if (isCancelled) {
|
||||
_log.warning("Hashing cancelled. Stopped processing albums.");
|
||||
break;
|
||||
}
|
||||
final trashedToHash = await _trashSyncService.getAssetsToHash(album.id);
|
||||
if (backupAlbums.isNotEmpty) {
|
||||
final backupAlbumIds = backupAlbums.map((e) => e.id);
|
||||
final trashedToHash = await _trashSyncService.getAssetsToHash(backupAlbumIds);
|
||||
if (trashedToHash.isNotEmpty) {
|
||||
await _hashTrashedAssets(album, trashedToHash);
|
||||
for (final album in backupAlbums) {
|
||||
if (isCancelled) {
|
||||
_log.warning("Hashing cancelled. Stopped processing albums.");
|
||||
break;
|
||||
}
|
||||
await _hashTrashedAssets(album, trashedToHash.where((e) => e.albumId == album.id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,8 +45,8 @@ class TrashSyncService {
|
|||
Future<void> updateChecksums(Iterable<TrashedAsset> assets) async =>
|
||||
_trashedLocalAssetRepository.updateChecksums(assets);
|
||||
|
||||
Future<Iterable<TrashedAsset>> getAssetsToHash(String albumId) async =>
|
||||
_trashedLocalAssetRepository.getToHash(albumId);
|
||||
Future<Iterable<TrashedAsset>> getAssetsToHash(Iterable<String> albumIds) async =>
|
||||
_trashedLocalAssetRepository.getToHash(albumIds);
|
||||
|
||||
Future<void> syncDeviceTrashSnapshot() async {
|
||||
final backupAlbums = await _localAlbumRepository.getBackupAlbums();
|
||||
|
|
@ -60,7 +60,7 @@ class TrashSyncService {
|
|||
final trashedAssets = trashedPlatformAssets.toTrashedAssets(album.id);
|
||||
await _trashedLocalAssetRepository.applyTrashSnapshot(trashedAssets, album.id);
|
||||
}
|
||||
await applyRemoteRestoreToLocal();
|
||||
await _applyRemoteRestoreToLocal();
|
||||
}
|
||||
|
||||
Future<void> applyTrashDelta(SyncDelta delta) async {
|
||||
|
|
@ -76,8 +76,8 @@ class TrashSyncService {
|
|||
}
|
||||
}
|
||||
_logger.info("updateLocalTrashChanges trashedAssets: ${trashedAssets.map((e) => e.id)}");
|
||||
await _trashedLocalAssetRepository.insertTrashDelta(trashedAssets);
|
||||
await applyRemoteRestoreToLocal();
|
||||
await _trashedLocalAssetRepository.saveTrashedAssets(trashedAssets);
|
||||
await _applyRemoteRestoreToLocal();
|
||||
}
|
||||
|
||||
Future<void> handleRemoteTrashed(Iterable<String> checksums) async {
|
||||
|
|
@ -102,7 +102,7 @@ class TrashSyncService {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> applyRemoteRestoreToLocal() async {
|
||||
Future<void> _applyRemoteRestoreToLocal() async {
|
||||
final remoteAssetsToRestore = await _trashedLocalAssetRepository.getToRestore();
|
||||
if (remoteAssetsToRestore.isNotEmpty) {
|
||||
_logger.info("remoteAssetsToRestore: $remoteAssetsToRestore");
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ class DriftTrashedLocalAssetRepository extends DriftDatabaseRepository {
|
|||
});
|
||||
}
|
||||
|
||||
Future<Iterable<TrashedAsset>> getToHash(String albumId) {
|
||||
final query = _db.trashedLocalAssetEntity.select()..where((r) => r.albumId.equals(albumId) & r.checksum.isNull());
|
||||
Future<Iterable<TrashedAsset>> getToHash(Iterable<String> albumIds) {
|
||||
final query = _db.trashedLocalAssetEntity.select()..where((r) => r.albumId.isIn(albumIds) & r.checksum.isNull());
|
||||
return query.map((row) => row.toDto()).get();
|
||||
}
|
||||
|
||||
|
|
@ -100,7 +100,7 @@ class DriftTrashedLocalAssetRepository extends DriftDatabaseRepository {
|
|||
});
|
||||
}
|
||||
|
||||
Future<void> insertTrashDelta(Iterable<TrashedAsset> trashUpdates) async {
|
||||
Future<void> saveTrashedAssets(Iterable<TrashedAsset> trashUpdates) async {
|
||||
if (trashUpdates.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue