refactor: asset update method (#30201)

Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
This commit is contained in:
shenlong
2026-07-27 10:15:36 -04:00
committed by GitHub
co-authored by shenlong-tanwen
parent bc6bf388c0
commit 04a38ba91c
32 changed files with 700 additions and 134 deletions
@@ -72,13 +72,7 @@ class RemoteAssetRepository extends DriftDatabaseRepository {
}
final query = _db.remoteAssetEntity.select()
..where(
(row) =>
row.stackId.equals(stackId) &
row.id.equals(asset.id).not() &
row.deletedAt.isNull() &
row.visibility.equalsValue(AssetVisibility.timeline),
)
..where((row) => row.stackId.equals(stackId) & row.id.equals(asset.id).not())
..orderBy([(row) => OrderingTerm.desc(row.createdAt)]);
return query.map((row) => row.toDto()).get();
@@ -189,38 +183,6 @@ class RemoteAssetRepository extends DriftDatabaseRepository {
});
}
Future<void> updateLocation(List<String> ids, LatLng location) {
return _db.batch((batch) async {
for (final id in ids) {
batch.update(
_db.remoteExifEntity,
RemoteExifEntityCompanion(latitude: Value(location.latitude), longitude: Value(location.longitude)),
where: (e) => e.assetId.equals(id),
);
}
});
}
Future<void> updateDateTime(List<String> ids, DateTime dateTime, {String? timeZone}) {
return _db.batch((batch) async {
for (final id in ids) {
batch.update(
_db.remoteExifEntity,
RemoteExifEntityCompanion(
dateTimeOriginal: Value(dateTime),
timeZone: timeZone == null ? const Value.absent() : Value(timeZone),
),
where: (e) => e.assetId.equals(id),
);
batch.update(
_db.remoteAssetEntity,
RemoteAssetEntityCompanion(createdAt: Value(dateTime)),
where: (e) => e.id.equals(id),
);
}
});
}
Future<void> stack(String userId, StackResponse stack) {
return _db.transaction(() async {
final stackIds = await _db.managers.stackEntity
@@ -298,10 +260,16 @@ class RemoteAssetRepository extends DriftDatabaseRepository {
List<String> remoteIds, {
Option<bool> isFavorite = const .none(),
Option<AssetVisibility> visibility = const .none(),
}) {
Option<DateTime> createdAt = const .none(),
}) async {
if ([isFavorite, visibility, createdAt].every((option) => option.isNone)) {
return;
}
final companion = RemoteAssetEntityCompanion(
visibility: visibility.toDriftValue(),
isFavorite: isFavorite.toDriftValue(),
createdAt: createdAt.toDriftValue(),
);
return _db.batch((batch) {
for (final remoteId in remoteIds) {
@@ -309,4 +277,37 @@ class RemoteAssetRepository extends DriftDatabaseRepository {
}
});
}
// TODO(shenlong): remove after action migration
Future<void> updateLocation(List<String> ids, LatLng location) {
return _db.batch((batch) async {
for (final id in ids) {
batch.update(
_db.remoteExifEntity,
RemoteExifEntityCompanion(latitude: Value(location.latitude), longitude: Value(location.longitude)),
where: (e) => e.assetId.equals(id),
);
}
});
}
Future<void> updateDateTime(List<String> ids, DateTime dateTime, {String? timeZone}) {
return _db.batch((batch) async {
for (final id in ids) {
batch.update(
_db.remoteExifEntity,
RemoteExifEntityCompanion(
dateTimeOriginal: Value(dateTime),
timeZone: timeZone == null ? const Value.absent() : Value(timeZone),
),
where: (e) => e.assetId.equals(id),
);
batch.update(
_db.remoteAssetEntity,
RemoteAssetEntityCompanion(createdAt: Value(dateTime)),
where: (e) => e.id.equals(id),
);
}
});
}
}
@@ -0,0 +1,34 @@
import 'package:immich_mobile/infrastructure/entities/exif.entity.drift.dart';
import 'package:immich_mobile/infrastructure/repositories/db.repository.dart';
import 'package:immich_mobile/utils/option.dart';
import 'package:maplibre_gl/maplibre_gl.dart';
class RemoteExifRepository extends DriftDatabaseRepository {
final Drift _db;
const RemoteExifRepository(this._db) : super(_db);
Future<void> update(
List<String> ids, {
Option<DateTime> dateTimeOriginal = const .none(),
Option<String> timeZone = const .none(),
Option<LatLng> location = const .none(),
}) async {
if ([dateTimeOriginal, timeZone, location].every((option) => option.isNone)) {
return;
}
final companion = RemoteExifEntityCompanion(
dateTimeOriginal: dateTimeOriginal.toDriftValue(),
timeZone: timeZone.toDriftValue(),
latitude: location.map((loc) => loc.latitude).toDriftValue(),
longitude: location.map((loc) => loc.longitude).toDriftValue(),
);
return _db.batch((batch) {
for (final id in ids) {
batch.update(_db.remoteExifEntity, companion, where: (a) => a.assetId.equals(id));
}
});
}
}