mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
Include trashed items in getMediaChanges
Process trashed items delta during incremental sync
This commit is contained in:
parent
5ddb6cd2e1
commit
55fe480cc1
9 changed files with 110 additions and 36 deletions
|
|
@ -15,12 +15,12 @@ class DriftTrashedLocalAssetRepository extends DriftDatabaseRepository {
|
|||
if (assets.isEmpty) {
|
||||
return Future.value();
|
||||
}
|
||||
|
||||
final now = DateTime.now();
|
||||
return _db.batch((batch) async {
|
||||
for (final asset in assets) {
|
||||
batch.update(
|
||||
_db.trashedLocalAssetEntity,
|
||||
TrashedLocalAssetEntityCompanion(checksum: Value(asset.checksum)),
|
||||
TrashedLocalAssetEntityCompanion(checksum: Value(asset.checksum), updatedAt: Value(now)),
|
||||
where: (e) => e.id.equals(asset.id),
|
||||
);
|
||||
}
|
||||
|
|
@ -95,6 +95,30 @@ class DriftTrashedLocalAssetRepository extends DriftDatabaseRepository {
|
|||
});
|
||||
}
|
||||
|
||||
Future<void> insertTrashDelta(Iterable<TrashedAsset> trashUpdates) async {
|
||||
if (trashUpdates.isEmpty) {
|
||||
return;
|
||||
}
|
||||
final companions = trashUpdates
|
||||
.map(
|
||||
(a) => TrashedLocalAssetEntityCompanion.insert(
|
||||
id: a.id,
|
||||
albumId: a.albumId,
|
||||
name: a.name,
|
||||
type: a.type,
|
||||
checksum: a.checksum == null ? const Value.absent() : Value(a.checksum),
|
||||
size: a.size == null ? const Value.absent() : Value(a.size),
|
||||
createdAt: Value(a.createdAt),
|
||||
),
|
||||
);
|
||||
|
||||
for (final slice in companions.slices(200)) {
|
||||
await _db.batch((b) {
|
||||
b.insertAllOnConflictUpdate(_db.trashedLocalAssetEntity, slice);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Stream<int> watchCount() {
|
||||
final t = _db.trashedLocalAssetEntity;
|
||||
return (_db.selectOnly(t)..addColumns([t.id.count()])).watchSingle().map((row) => row.read<int>(t.id.count()) ?? 0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue