mirror of
https://github.com/immich-app/immich.git
synced 2025-12-10 23:25:29 -05:00
store cloudId in sqlite
This commit is contained in:
parent
ecbaca3cee
commit
61e079a63e
@ -3,11 +3,13 @@ part of 'base_asset.model.dart';
|
|||||||
class LocalAsset extends BaseAsset {
|
class LocalAsset extends BaseAsset {
|
||||||
final String id;
|
final String id;
|
||||||
final String? remoteId;
|
final String? remoteId;
|
||||||
|
final String? cloudId;
|
||||||
final int orientation;
|
final int orientation;
|
||||||
|
|
||||||
const LocalAsset({
|
const LocalAsset({
|
||||||
required this.id,
|
required this.id,
|
||||||
this.remoteId,
|
this.remoteId,
|
||||||
|
this.cloudId,
|
||||||
required super.name,
|
required super.name,
|
||||||
super.checksum,
|
super.checksum,
|
||||||
required super.type,
|
required super.type,
|
||||||
@ -31,6 +33,8 @@ class LocalAsset extends BaseAsset {
|
|||||||
String toString() {
|
String toString() {
|
||||||
return '''LocalAsset {
|
return '''LocalAsset {
|
||||||
id: $id,
|
id: $id,
|
||||||
|
remoteId: ${remoteId ?? "<NA>"},
|
||||||
|
cloudId: ${cloudId ?? "<NA>"},
|
||||||
name: $name,
|
name: $name,
|
||||||
type: $type,
|
type: $type,
|
||||||
createdAt: $createdAt,
|
createdAt: $createdAt,
|
||||||
@ -49,7 +53,7 @@ class LocalAsset extends BaseAsset {
|
|||||||
bool operator ==(Object other) {
|
bool operator ==(Object other) {
|
||||||
if (other is! LocalAsset) return false;
|
if (other is! LocalAsset) return false;
|
||||||
if (identical(this, other)) return true;
|
if (identical(this, other)) return true;
|
||||||
return super == other && id == other.id && orientation == other.orientation;
|
return super == other && id == other.id && orientation == other.orientation && cloudId == other.cloudId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -58,6 +62,7 @@ class LocalAsset extends BaseAsset {
|
|||||||
LocalAsset copyWith({
|
LocalAsset copyWith({
|
||||||
String? id,
|
String? id,
|
||||||
String? remoteId,
|
String? remoteId,
|
||||||
|
String? cloudId,
|
||||||
String? name,
|
String? name,
|
||||||
String? checksum,
|
String? checksum,
|
||||||
AssetType? type,
|
AssetType? type,
|
||||||
@ -72,6 +77,7 @@ class LocalAsset extends BaseAsset {
|
|||||||
return LocalAsset(
|
return LocalAsset(
|
||||||
id: id ?? this.id,
|
id: id ?? this.id,
|
||||||
remoteId: remoteId ?? this.remoteId,
|
remoteId: remoteId ?? this.remoteId,
|
||||||
|
cloudId: cloudId ?? this.cloudId,
|
||||||
name: name ?? this.name,
|
name: name ?? this.name,
|
||||||
checksum: checksum ?? this.checksum,
|
checksum: checksum ?? this.checksum,
|
||||||
type: type ?? this.type,
|
type: type ?? this.type,
|
||||||
|
|||||||
@ -73,6 +73,12 @@ class LocalSyncService {
|
|||||||
}
|
}
|
||||||
await updateAlbum(dbAlbum, album);
|
await updateAlbum(dbAlbum, album);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final newAssetIds = delta.updates.map((e) => e.id).toList();
|
||||||
|
if (newAssetIds.isNotEmpty) {
|
||||||
|
final cloudMapping = await _nativeSyncApi.getCloudIdForAssetIds(newAssetIds);
|
||||||
|
await _localAlbumRepository.updateCloudMapping(cloudMapping);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await _nativeSyncApi.checkpointSync();
|
await _nativeSyncApi.checkpointSync();
|
||||||
|
|||||||
@ -16,6 +16,8 @@ class LocalAssetEntity extends Table with DriftDefaultsMixin, AssetEntityMixin {
|
|||||||
|
|
||||||
IntColumn get orientation => integer().withDefault(const Constant(0))();
|
IntColumn get orientation => integer().withDefault(const Constant(0))();
|
||||||
|
|
||||||
|
TextColumn get cloudId => text().nullable()();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Set<Column> get primaryKey => {id};
|
Set<Column> get primaryKey => {id};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -97,6 +97,8 @@ class Drift extends $Drift implements IDatabaseRepository {
|
|||||||
await m.create(v4.assetFaceEntity);
|
await m.create(v4.assetFaceEntity);
|
||||||
},
|
},
|
||||||
from4To5: (m, v5) async {
|
from4To5: (m, v5) async {
|
||||||
|
// Add cloudId column to local_asset_entity
|
||||||
|
await m.addColumn(v5.localAssetEntity, v5.localAssetEntity.cloudId);
|
||||||
await m.alterTable(
|
await m.alterTable(
|
||||||
TableMigration(
|
TableMigration(
|
||||||
v5.userEntity,
|
v5.userEntity,
|
||||||
|
|||||||
@ -231,6 +231,25 @@ class DriftLocalAlbumRepository extends DriftDatabaseRepository {
|
|||||||
return query.map((row) => row.readTable(_db.localAssetEntity).toDto()).get();
|
return query.map((row) => row.readTable(_db.localAssetEntity).toDto()).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> updateCloudMapping(Map<String, String?> cloudMapping) {
|
||||||
|
if (cloudMapping.isEmpty) {
|
||||||
|
return Future.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
return _db.batch((batch) {
|
||||||
|
for (final entry in cloudMapping.entries) {
|
||||||
|
final assetId = entry.key;
|
||||||
|
final cloudId = entry.value;
|
||||||
|
|
||||||
|
batch.update(
|
||||||
|
_db.localAssetEntity,
|
||||||
|
LocalAssetEntityCompanion(cloudId: Value(cloudId)),
|
||||||
|
where: (f) => f.id.equals(assetId),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _upsertAssets(Iterable<LocalAsset> localAssets) {
|
Future<void> _upsertAssets(Iterable<LocalAsset> localAssets) {
|
||||||
if (localAssets.isEmpty) {
|
if (localAssets.isEmpty) {
|
||||||
return Future.value();
|
return Future.value();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user