From d03d8d564de5cb177e2ffa06263dc872ead6cf0e Mon Sep 17 00:00:00 2001 From: laurenspriem Date: Mon, 29 Apr 2024 15:13:51 +0530 Subject: [PATCH] [mob][photos] Fix DB issue --- mobile/lib/face/db.dart | 69 +++++++++++++++------------------- mobile/lib/face/db_fields.dart | 2 +- 2 files changed, 31 insertions(+), 40 deletions(-) diff --git a/mobile/lib/face/db.dart b/mobile/lib/face/db.dart index 594f9aa4f..14f710017 100644 --- a/mobile/lib/face/db.dart +++ b/mobile/lib/face/db.dart @@ -191,13 +191,11 @@ class FaceMLDataDB { Future clearTable() async { final db = await instance.asyncDB; - await db.writeTransaction((tx) async { - await tx.execute(deleteFacesTable); - await tx.execute(dropClusterPersonTable); - await tx.execute(dropClusterSummaryTable); - await tx.execute(deletePersonTable); - await tx.execute(dropNotPersonFeedbackTable); - }); + await db.execute(deleteFacesTable); + await db.execute(dropClusterPersonTable); + await db.execute(dropClusterSummaryTable); + await db.execute(deletePersonTable); + await db.execute(dropNotPersonFeedbackTable); } Future> getFaceEmbeddingsForCluster( @@ -728,11 +726,9 @@ class FaceMLDataDB { try { final db = await instance.asyncDB; - await db.writeTransaction((tx) async { - await tx.execute(dropFaceClustersTable); - await tx.execute(createFaceClustersTable); - await tx.execute(fcClusterIDIndex); - }); + await db.execute(dropFaceClustersTable); + await db.execute(createFaceClustersTable); + await db.execute(fcClusterIDIndex); } catch (e, s) { _logger.severe('Error resetting clusterIDs', e, s); } @@ -964,27 +960,21 @@ class FaceMLDataDB { try { final db = await instance.asyncDB; if (faces) { - await db.writeTransaction((tx) async { - await tx.execute(deleteFacesTable); - await tx.execute(createFacesTable); - await tx.execute(dropFaceClustersTable); - await tx.execute(createFaceClustersTable); - await tx.execute(fcClusterIDIndex); - }); + await db.execute(deleteFacesTable); + await db.execute(createFacesTable); + await db.execute(dropFaceClustersTable); + await db.execute(createFaceClustersTable); + await db.execute(fcClusterIDIndex); } - await db.writeTransaction((tx) async { - await tx.execute(deletePersonTable); - await tx.execute(dropClusterPersonTable); - await tx.execute(dropClusterSummaryTable); - await tx.execute(dropNotPersonFeedbackTable); - }); + await db.execute(deletePersonTable); + await db.execute(dropClusterPersonTable); + await db.execute(dropClusterSummaryTable); + await db.execute(dropNotPersonFeedbackTable); - await db.writeTransaction((tx) async { - await tx.execute(createClusterPersonTable); - await tx.execute(createNotPersonFeedbackTable); - await tx.execute(createClusterSummaryTable); - }); + await db.execute(createClusterPersonTable); + await db.execute(createNotPersonFeedbackTable); + await db.execute(createClusterSummaryTable); } catch (e, s) { _logger.severe('Error dropping clusters and person table', e, s); } @@ -995,15 +985,16 @@ class FaceMLDataDB { try { final db = await instance.asyncDB; - await db.writeTransaction((tx) async { - await tx.execute(deletePersonTable); - await tx.execute(dropClusterPersonTable); - await tx.execute(dropNotPersonFeedbackTable); - await tx.execute(dropClusterSummaryTable); - await tx.execute(createClusterPersonTable); - await tx.execute(createNotPersonFeedbackTable); - await tx.execute(createClusterSummaryTable); - }); + // Drop the tables + await db.execute(deletePersonTable); + await db.execute(dropClusterPersonTable); + await db.execute(dropNotPersonFeedbackTable); + await db.execute(dropClusterSummaryTable); + + // Recreate the tables + await db.execute(createClusterPersonTable); + await db.execute(createNotPersonFeedbackTable); + await db.execute(createClusterSummaryTable); } catch (e) { _logger.severe('Error dropping feedback tables', e); } diff --git a/mobile/lib/face/db_fields.dart b/mobile/lib/face/db_fields.dart index 863b1cc78..e6a70a7d4 100644 --- a/mobile/lib/face/db_fields.dart +++ b/mobile/lib/face/db_fields.dart @@ -95,7 +95,7 @@ const notPersonFeedback = 'not_person_feedback'; const createNotPersonFeedbackTable = ''' CREATE TABLE IF NOT EXISTS $notPersonFeedback ( $personIdColumn TEXT NOT NULL, - $clusterIDColumn INTEGER NOT NULL + $clusterIDColumn INTEGER NOT NULL, PRIMARY KEY($personIdColumn, $clusterIDColumn) ); ''';