From f7697264eddcfb8815742ed93fadf0afa19df3dd Mon Sep 17 00:00:00 2001 From: Ethan Ferrier Date: Thu, 29 Oct 2026 04:31:54 -0500 Subject: [PATCH] fix(mobile): ocr delete by asset (#32611) (cherry picked from commit 56ed326acda2220fc7e3b21b17b3c8d24daf99cc) --- .../repositories/sync_stream.repository.dart | 2 +- .../sync_stream_repository_test.dart | 61 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/mobile/lib/infrastructure/repositories/sync_stream.repository.dart b/mobile/lib/infrastructure/repositories/sync_stream.repository.dart index e599e12ee..46c13dc2d 100644 --- a/mobile/lib/infrastructure/repositories/sync_stream.repository.dart +++ b/mobile/lib/infrastructure/repositories/sync_stream.repository.dart @@ -923,7 +923,7 @@ class SyncStreamRepository extends DatabaseAccessor with $SyncStreamRepos try { await _db.batch((batch) { 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) { diff --git a/mobile/test/domain/repositories/sync_stream_repository_test.dart b/mobile/test/domain/repositories/sync_stream_repository_test.dart index 2e5809cd6..53756dfc9 100644 --- a/mobile/test/domain/repositories/sync_stream_repository_test.dart +++ b/mobile/test/domain/repositories/sync_stream_repository_test.dart @@ -363,4 +363,65 @@ void main() { 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)); + }); + }); }