more fixes

This commit is contained in:
shenlong-tanwen
2025-09-04 18:28:02 +05:30
parent 254ca4a13d
commit 9cf5d83707
6 changed files with 41 additions and 29 deletions
+18 -5
View File
@@ -7,6 +7,8 @@ import 'package:immich_mobile/platform/native_sync_api.g.dart';
import 'package:immich_mobile/providers/api.provider.dart';
import 'package:immich_mobile/providers/infrastructure/db.provider.dart';
import 'package:immich_mobile/providers/infrastructure/sync.provider.dart';
import 'package:immich_mobile/providers/user.provider.dart';
import 'package:logging/logging.dart';
// ignore: import_rule_openapi
import 'package:openapi/api.dart';
@@ -19,14 +21,24 @@ Future<void> migrateCloudIds(ProviderContainer ref) async {
await ref.read(syncStreamServiceProvider).sync();
// Fetch the mapping for backed up assets that have a cloud ID locally but do not have a cloud ID on the server
final mappingsToUpdate = await _fetchCloudIdMappings(db);
final currentUser = ref.read(currentUserProvider);
if (currentUser == null) {
Logger('migrateCloudIds').warning('Current user is null. Aborting cloudId migration.');
return;
}
final mappingsToUpdate = await _fetchCloudIdMappings(db, currentUser.id);
final assetApi = ref.read(apiServiceProvider).assetsApi;
for (final mapping in mappingsToUpdate) {
final mobileMeta = AssetMetadataUpsertItemDto(
key: AssetMetadataKey.mobileApp,
value: RemoteAssetMobileAppMetadata(cloudId: mapping.cloudId).toMap(),
value: RemoteAssetMobileAppMetadata(cloudId: mapping.cloudId),
);
await assetApi.updateAssetMetadata(mapping.assetId, AssetMetadataUpsertDto(items: [mobileMeta]));
try {
await assetApi.updateAssetMetadata(mapping.assetId, AssetMetadataUpsertDto(items: [mobileMeta]));
} catch (error, stack) {
Logger('migrateCloudIds').warning('Failed to update metadata for asset ${mapping.assetId}', error, stack);
}
}
}
@@ -41,7 +53,7 @@ Future<void> _populateCloudIds(Drift drift) async {
typedef _CloudIdMapping = ({String assetId, String cloudId});
Future<List<_CloudIdMapping>> _fetchCloudIdMappings(Drift drift) async {
Future<List<_CloudIdMapping>> _fetchCloudIdMappings(Drift drift, String userId) async {
final query =
drift.remoteAssetEntity.selectOnly().join([
leftOuterJoin(
@@ -58,7 +70,8 @@ Future<List<_CloudIdMapping>> _fetchCloudIdMappings(Drift drift) async {
])
..addColumns([drift.remoteAssetEntity.id, drift.localAssetEntity.cloudId])
..where(
drift.localAssetEntity.id.isNotNull() &
drift.remoteAssetEntity.ownerId.equals(userId) &
drift.localAssetEntity.id.isNotNull() &
drift.localAssetEntity.cloudId.isNotNull() &
drift.remoteAssetMetadataEntity.cloudId.isNull(),
);