fix(mobile): ocr delete by asset (#32611)

(cherry picked from commit 56ed326acda2220fc7e3b21b17b3c8d24daf99cc)
This commit is contained in:
Ethan Ferrier
2026-10-29 20:43:01 +03:00
committed by Codex
parent 648dea2072
commit f7697264ed
2 changed files with 62 additions and 1 deletions
@@ -923,7 +923,7 @@ class SyncStreamRepository extends DatabaseAccessor<Drift> with $SyncStreamRepos
try { try {
await _db.batch((batch) { await _db.batch((batch) {
for (final assetOcr in data) { for (final assetOcr in data) {
batch.deleteWhere(_db.assetOcrEntity, (row) => row.id.equals(assetOcr.id)); batch.deleteWhere(_db.assetOcrEntity, (row) => row.assetId.equals(assetOcr.assetId));
} }
}); });
} catch (error, stack) { } catch (error, stack) {
@@ -363,4 +363,65 @@ void main() {
expect(rows.map((r) => r.id).toSet(), {last.id, lastLib.id}); expect(rows.map((r) => r.id).toSet(), {last.id, lastLib.id});
}); });
}); });
group('SyncStreamRepository - deleteAssetOcrV1 (#32337)', () {
test('removes OCR rows for deleted assets', () async {
await sut.updateUsersV1([_createUser()]);
final known1 = _createAsset(
id: 'known1',
checksum: 'AAA',
fileName: 'a.jpg',
);
final known2 = _createAsset(
id: 'known2',
checksum: 'BBB',
fileName: 'b.jpg',
);
await sut.updateAssetsV1([known1, known2]);
await sut.updateAssetOcrV1([
SyncAssetOcrV1(
assetId: known1.id,
boxScore: 0.9,
id: 'ocr-1',
isVisible: true,
text: 'this text',
textScore: 0.9,
x1: 1,
x2: 2,
x3: 3,
x4: 4,
y1: 1,
y2: 2,
y3: 3,
y4: 4,
),
SyncAssetOcrV1(
assetId: known2.id,
boxScore: 0.8,
id: 'ocr-2',
isVisible: false,
text: 'this text again',
textScore: 0.8,
x1: 1,
x2: 2,
x3: 3,
x4: 4,
y1: 1,
y2: 2,
y3: 3,
y4: 4,
),
]);
await sut.deleteAssetOcrV1([
SyncAssetOcrDeleteV1(id: 'log-id', assetId: known1.id, deletedAt: DateTime(2024, 1, 5)),
]);
final removedRows = await (db.assetOcrEntity.select()..where((t) => t.assetId.equals(known1.id))).get();
expect(removedRows, isEmpty);
final keepRows = await (db.assetOcrEntity.select()..where((t) => t.assetId.equals(known2.id))).get();
expect(keepRows, hasLength(1));
});
});
} }