more fixes
This commit is contained in:
@@ -64,7 +64,8 @@ class DriftBackupRepository extends DriftDatabaseRepository {
|
||||
),
|
||||
leftOuterJoin(
|
||||
_db.remoteAssetEntity,
|
||||
_db.localAssetEntity.checksum.equalsExp(_db.remoteAssetEntity.checksum) &
|
||||
(_db.localAssetEntity.checksum.equalsExp(_db.remoteAssetEntity.checksum) |
|
||||
_db.localAssetEntity.cloudId.equalsExp(_db.remoteAssetEntity.cloudId)) &
|
||||
_db.remoteAssetEntity.ownerId.equals(userId),
|
||||
useColumns: false,
|
||||
),
|
||||
@@ -94,7 +95,8 @@ class DriftBackupRepository extends DriftDatabaseRepository {
|
||||
),
|
||||
innerJoin(
|
||||
_db.remoteAssetEntity,
|
||||
_db.localAssetEntity.checksum.equalsExp(_db.remoteAssetEntity.checksum),
|
||||
_db.localAssetEntity.checksum.equalsExp(_db.remoteAssetEntity.checksum) |
|
||||
_db.localAssetEntity.cloudId.equalsExp(_db.remoteAssetEntity.cloudId),
|
||||
useColumns: false,
|
||||
),
|
||||
])
|
||||
@@ -116,7 +118,7 @@ class DriftBackupRepository extends DriftDatabaseRepository {
|
||||
final query = _db.localAssetEntity.select()
|
||||
..where(
|
||||
(lae) =>
|
||||
lae.checksum.isNotNull() &
|
||||
(lae.checksum.isNotNull() | lae.cloudId.isNotNull()) &
|
||||
existsQuery(
|
||||
_db.localAlbumAssetEntity.selectOnly()
|
||||
..addColumns([_db.localAlbumAssetEntity.assetId])
|
||||
@@ -129,7 +131,9 @@ class DriftBackupRepository extends DriftDatabaseRepository {
|
||||
_db.remoteAssetEntity.selectOnly()
|
||||
..addColumns([_db.remoteAssetEntity.checksum])
|
||||
..where(
|
||||
_db.remoteAssetEntity.checksum.equalsExp(lae.checksum) & _db.remoteAssetEntity.ownerId.equals(userId),
|
||||
(_db.localAssetEntity.checksum.equalsExp(_db.remoteAssetEntity.checksum) |
|
||||
_db.localAssetEntity.cloudId.equalsExp(_db.remoteAssetEntity.cloudId)) &
|
||||
_db.remoteAssetEntity.ownerId.equals(userId),
|
||||
),
|
||||
) &
|
||||
lae.id.isNotInQuery(_getExcludedSubquery()),
|
||||
|
||||
@@ -17,7 +17,6 @@ import 'package:immich_mobile/infrastructure/entities/remote_album.entity.dart';
|
||||
import 'package:immich_mobile/infrastructure/entities/remote_album_asset.entity.dart';
|
||||
import 'package:immich_mobile/infrastructure/entities/remote_album_user.entity.dart';
|
||||
import 'package:immich_mobile/infrastructure/entities/remote_asset.entity.dart';
|
||||
import 'package:immich_mobile/infrastructure/entities/remote_asset_metadata.entity.dart';
|
||||
import 'package:immich_mobile/infrastructure/entities/stack.entity.dart';
|
||||
import 'package:immich_mobile/infrastructure/entities/store.entity.dart';
|
||||
import 'package:immich_mobile/infrastructure/entities/user.entity.dart';
|
||||
@@ -51,7 +50,6 @@ class IsarDatabaseRepository implements IDatabaseRepository {
|
||||
LocalAssetEntity,
|
||||
LocalAlbumAssetEntity,
|
||||
RemoteAssetEntity,
|
||||
RemoteAssetMetadataEntity,
|
||||
RemoteExifEntity,
|
||||
RemoteAlbumEntity,
|
||||
RemoteAlbumAssetEntity,
|
||||
@@ -129,9 +127,9 @@ class Drift extends $Drift implements IDatabaseRepository {
|
||||
// Add cloudId column to local_asset_entity
|
||||
await m.addColumn(v9.localAssetEntity, v9.localAssetEntity.cloudId);
|
||||
await m.createIndex(v9.idxLocalAssetCloudId);
|
||||
// Create new table
|
||||
await m.createTable(v9.remoteAssetMetadataEntity);
|
||||
await m.createIndex(v9.uQRemoteAssetMetadataCloudId);
|
||||
// Add cloudId column to remote_asset_entity
|
||||
await m.addColumn(v9.remoteAssetEntity, v9.remoteAssetEntity.cloudId);
|
||||
await m.createIndex(v9.idxRemoteAssetCloudId);
|
||||
},
|
||||
from8To9: (m, v9) async {
|
||||
await m.addColumn(v9.localAlbumEntity, v9.localAlbumEntity.linkedRemoteAlbumId);
|
||||
|
||||
@@ -13,7 +13,8 @@ class DriftLocalAssetRepository extends DriftDatabaseRepository {
|
||||
final query = _db.localAssetEntity.select().addColumns([_db.remoteAssetEntity.id]).join([
|
||||
leftOuterJoin(
|
||||
_db.remoteAssetEntity,
|
||||
_db.localAssetEntity.checksum.equalsExp(_db.remoteAssetEntity.checksum),
|
||||
_db.localAssetEntity.checksum.equalsExp(_db.remoteAssetEntity.checksum) |
|
||||
_db.localAssetEntity.cloudId.equalsExp(_db.remoteAssetEntity.cloudId),
|
||||
useColumns: false,
|
||||
),
|
||||
])..where(_db.localAssetEntity.id.equals(id));
|
||||
|
||||
@@ -34,7 +34,8 @@ class RemoteAssetRepository extends DriftDatabaseRepository {
|
||||
_db.remoteAssetEntity.select().addColumns([_db.localAssetEntity.id]).join([
|
||||
leftOuterJoin(
|
||||
_db.localAssetEntity,
|
||||
_db.remoteAssetEntity.checksum.equalsExp(_db.localAssetEntity.checksum),
|
||||
_db.localAssetEntity.checksum.equalsExp(_db.remoteAssetEntity.checksum) |
|
||||
_db.localAssetEntity.cloudId.equalsExp(_db.remoteAssetEntity.cloudId),
|
||||
useColumns: false,
|
||||
),
|
||||
])
|
||||
|
||||
@@ -15,14 +15,13 @@ import 'package:immich_mobile/infrastructure/entities/remote_album.entity.drift.
|
||||
import 'package:immich_mobile/infrastructure/entities/remote_album_asset.entity.drift.dart';
|
||||
import 'package:immich_mobile/infrastructure/entities/remote_album_user.entity.drift.dart';
|
||||
import 'package:immich_mobile/infrastructure/entities/remote_asset.entity.drift.dart';
|
||||
import 'package:immich_mobile/infrastructure/entities/remote_asset_metadata.entity.drift.dart';
|
||||
import 'package:immich_mobile/infrastructure/entities/stack.entity.drift.dart';
|
||||
import 'package:immich_mobile/infrastructure/entities/user.entity.drift.dart';
|
||||
import 'package:immich_mobile/infrastructure/entities/user_metadata.entity.drift.dart';
|
||||
import 'package:immich_mobile/infrastructure/repositories/db.repository.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:openapi/api.dart' as api show AssetVisibility, AlbumUserRole, UserMetadataKey;
|
||||
import 'package:openapi/api.dart' hide AssetVisibility, AlbumUserRole, UserMetadataKey, AssetMetadataKey;
|
||||
import 'package:openapi/api.dart' hide AssetVisibility, AlbumUserRole, UserMetadataKey;
|
||||
|
||||
class SyncStreamRepository extends DriftDatabaseRepository {
|
||||
final Logger _logger = Logger('DriftSyncStreamRepository');
|
||||
@@ -183,10 +182,13 @@ class SyncStreamRepository extends DriftDatabaseRepository {
|
||||
try {
|
||||
await _db.batch((batch) {
|
||||
for (final metadata in data) {
|
||||
batch.deleteWhere(
|
||||
_db.remoteAssetMetadataEntity,
|
||||
(row) => row.assetId.equals(metadata.assetId) & row.key.equals(metadata.key.value),
|
||||
);
|
||||
if (metadata.key == AssetMetadataKey.mobileApp) {
|
||||
batch.update(
|
||||
_db.remoteAssetEntity,
|
||||
const RemoteAssetEntityCompanion(cloudId: Value(null)),
|
||||
where: (row) => row.id.equals(metadata.assetId),
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (error, stack) {
|
||||
@@ -199,16 +201,14 @@ class SyncStreamRepository extends DriftDatabaseRepository {
|
||||
try {
|
||||
await _db.batch((batch) {
|
||||
for (final metadata in data) {
|
||||
final companion = RemoteAssetMetadataEntityCompanion(
|
||||
key: Value(metadata.key.value),
|
||||
value: Value(metadata.value as Map<String, Object?>),
|
||||
);
|
||||
|
||||
batch.insert(
|
||||
_db.remoteAssetMetadataEntity,
|
||||
companion.copyWith(assetId: Value(metadata.assetId)),
|
||||
onConflict: DoUpdate((_) => companion),
|
||||
);
|
||||
if (metadata.key == AssetMetadataKey.mobileApp) {
|
||||
final map = metadata.value as Map<String, Object?>;
|
||||
batch.update(
|
||||
_db.remoteAssetEntity,
|
||||
RemoteAssetEntityCompanion(cloudId: Value(map['iCloudId']?.toString())),
|
||||
where: (row) => row.id.equals(metadata.assetId),
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (error, stack) {
|
||||
|
||||
@@ -117,7 +117,8 @@ class DriftTimelineRepository extends DriftDatabaseRepository {
|
||||
),
|
||||
leftOuterJoin(
|
||||
_db.remoteAssetEntity,
|
||||
_db.localAssetEntity.checksum.equalsExp(_db.remoteAssetEntity.checksum),
|
||||
_db.localAssetEntity.checksum.equalsExp(_db.remoteAssetEntity.checksum) |
|
||||
_db.localAssetEntity.cloudId.equalsExp(_db.remoteAssetEntity.cloudId),
|
||||
useColumns: false,
|
||||
),
|
||||
])
|
||||
@@ -143,7 +144,8 @@ class DriftTimelineRepository extends DriftDatabaseRepository {
|
||||
),
|
||||
leftOuterJoin(
|
||||
_db.remoteAssetEntity,
|
||||
_db.localAssetEntity.checksum.equalsExp(_db.remoteAssetEntity.checksum),
|
||||
_db.localAssetEntity.checksum.equalsExp(_db.remoteAssetEntity.checksum) |
|
||||
_db.localAssetEntity.cloudId.equalsExp(_db.remoteAssetEntity.cloudId),
|
||||
useColumns: false,
|
||||
),
|
||||
])
|
||||
@@ -538,7 +540,8 @@ class DriftTimelineRepository extends DriftDatabaseRepository {
|
||||
_db.remoteAssetEntity.select().join([
|
||||
leftOuterJoin(
|
||||
_db.localAssetEntity,
|
||||
_db.remoteAssetEntity.checksum.equalsExp(_db.localAssetEntity.checksum),
|
||||
_db.localAssetEntity.checksum.equalsExp(_db.remoteAssetEntity.checksum) |
|
||||
_db.localAssetEntity.cloudId.equalsExp(_db.remoteAssetEntity.cloudId),
|
||||
useColumns: false,
|
||||
),
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user