π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Make pet vector ID columns UNIQUE and nullable
Amrithesh Kakkoth Entefc76ae6b82d7
diff --git a/mobile/apps/photos/lib/db/ml/db.dart b/mobile/apps/photos/lib/db/ml/db.dartindex 8b82fc69cf..a788b92b5a 100644--- a/mobile/apps/photos/lib/db/ml/db.dart+++ b/mobile/apps/photos/lib/db/ml/db.dart@@ -109,6 +109,10 @@ class MLDataDB with SqlDbBase implements IMLDataDB<int> {dropPetIndexedFilesTable,dropPetFaceClustersTable,dropPetClusterSummaryTable,+ dropPetFacesTable, // 23: recreate with UNIQUE faceVectorId+ createPetFacesTable,+ dropPetBodiesTable, // 25: recreate with UNIQUE bodyVectorId+ createPetBodiesTable,];static const List<String> _offlineMigrationScripts = [..._defaultMigrationScripts,diff --git a/mobile/apps/photos/lib/db/ml/db_pet_model_mappers.dart b/mobile/apps/photos/lib/db/ml/db_pet_model_mappers.dartindex fe2d1e04bf..ffcb4ff674 100644--- a/mobile/apps/photos/lib/db/ml/db_pet_model_mappers.dart+++ b/mobile/apps/photos/lib/db/ml/db_pet_model_mappers.dart@@ -9,7 +9,7 @@ class DBPetFace {final int fileId;final String petFaceId;final String detection;- final int faceVectorId;+ final int? faceVectorId;final int species;final double faceScore;final int imageHeight;@@ -49,7 +49,7 @@ class DBPetFace {fileId: fileId,petFaceId: '${fileId}_pet_0_0_0_0',detection: '{}',- faceVectorId: -1,+ faceVectorId: null,species: -1,faceScore: error ? -1.0 : 0.0,imageHeight: 0,@@ -63,7 +63,7 @@ class DBPetFace {fileId: map[fileIDColumn] as int,petFaceId: map[petFaceIDColumn] as String,detection: map[faceDetectionColumn] as String,- faceVectorId: map[faceVectorIdColumn] as int,+ faceVectorId: map[faceVectorIdColumn] as int?,species: map[speciesColumn] as int,faceScore: parseIntOrDoubleAsDouble(map['score']) ?? 0.0,imageHeight: map['height'] as int,@@ -80,7 +80,7 @@ class DBPetBody {final int fileId;final String petBodyId;final String detection;- final int bodyVectorId;+ final int? bodyVectorId;final int species;final double score;final int imageHeight;@@ -118,7 +118,7 @@ class DBPetBody {fileId: map[fileIDColumn] as int,petBodyId: map[petBodyIDColumn] as String,detection: map[detectionColumn] as String,- bodyVectorId: map[bodyVectorIdColumn] as int,+ bodyVectorId: map[bodyVectorIdColumn] as int?,species: map[speciesColumn] as int,score: parseIntOrDoubleAsDouble(map['score']) ?? 0.0,imageHeight: map['height'] as int,diff --git a/mobile/apps/photos/lib/db/ml/schema.dart b/mobile/apps/photos/lib/db/ml/schema.dartindex bb81a15d4b..6b40e73684 100644--- a/mobile/apps/photos/lib/db/ml/schema.dart+++ b/mobile/apps/photos/lib/db/ml/schema.dart@@ -201,7 +201,7 @@ const createPetFacesTable = '''CREATE TABLE IF NOT EXISTS $petFacesTable ($fileIDColumn INTEGER NOT NULL,$petFaceIDColumn TEXT NOT NULL UNIQUE,$faceDetectionColumn TEXT NOT NULL,- $faceVectorIdColumn INTEGER NOT NULL,+ $faceVectorIdColumn INTEGER UNIQUE,$speciesColumn INTEGER NOT NULL,$faceScore REAL NOT NULL,$imageHeight INTEGER NOT NULL DEFAULT 0,@@ -221,7 +221,7 @@ const createPetBodiesTable = '''CREATE TABLE IF NOT EXISTS $petBodiesTable ($fileIDColumn INTEGER NOT NULL,$petBodyIDColumn TEXT NOT NULL UNIQUE,$detectionColumn TEXT NOT NULL,- $bodyVectorIdColumn INTEGER NOT NULL,+ $bodyVectorIdColumn INTEGER UNIQUE,$speciesColumn INTEGER NOT NULL,$faceScore REAL NOT NULL,$imageHeight INTEGER NOT NULL DEFAULT 0,@@ -307,3 +307,7 @@ CREATE TABLE IF NOT EXISTS $petIndexedFilesTable (''';const dropPetIndexedFilesTable = 'DROP TABLE IF EXISTS $petIndexedFilesTable';++// ββ Recreate pet tables with UNIQUE vector ID columns ββ+const dropPetFacesTable = 'DROP TABLE IF EXISTS $petFacesTable';+const dropPetBodiesTable = 'DROP TABLE IF EXISTS $petBodiesTable';diff --git a/mobile/apps/photos/lib/services/machine_learning/ml_indexing_isolate.dart b/mobile/apps/photos/lib/services/machine_learning/ml_indexing_isolate.dartindex 0b77a06d68..802f394a27 100644--- a/mobile/apps/photos/lib/services/machine_learning/ml_indexing_isolate.dart+++ b/mobile/apps/photos/lib/services/machine_learning/ml_indexing_isolate.dart@@ -3,7 +3,8 @@ import "dart:io" show Platform;import "package:flutter/foundation.dart" show debugPrint;import "package:logging/logging.dart";-import "package:photos/service_locator.dart" show flagService, isOfflineMode, localSettings;+import "package:photos/service_locator.dart"+ show flagService, isOfflineMode, localSettings;import 'package:photos/services/machine_learning/face_ml/face_detection/face_detection_service.dart';import 'package:photos/services/machine_learning/face_ml/face_embedding/face_embedding_service.dart';import "package:photos/services/machine_learning/ml_models_overview.dart";diff --git a/mobile/apps/photos/lib/services/machine_learning/ml_result.dart b/mobile/apps/photos/lib/services/machine_learning/ml_result.dartindex 99e13543bc..9ffd28d79c 100644--- a/mobile/apps/photos/lib/services/machine_learning/ml_result.dart+++ b/mobile/apps/photos/lib/services/machine_learning/ml_result.dart@@ -71,8 +71,7 @@ class MLResult {petBodies: json['petBodies'] != null? (json['petBodies'] as List).map(- (item) =>- PetBodyResult.fromJson(item as Map<String, dynamic>),+ (item) => PetBodyResult.fromJson(item as Map<String, dynamic>),).toList(): null,diff --git a/mobile/apps/photos/lib/services/machine_learning/ml_service.dart b/mobile/apps/photos/lib/services/machine_learning/ml_service.dartindex 7064e2cd7d..113c8d04f5 100644--- a/mobile/apps/photos/lib/services/machine_learning/ml_service.dart+++ b/mobile/apps/photos/lib/services/machine_learning/ml_service.dart@@ -639,7 +639,7 @@ class MLService {fileId: result.fileId,petFaceId: pf.petFaceId,detection: jsonEncode(pf.detection.toJson()),- faceVectorId: -1,+ faceVectorId: null,species: pf.species,faceScore: pf.detection.score,imageHeight: result.decodedImageSize.height,@@ -670,7 +670,7 @@ class MLService {fileId: result.fileId,petBodyId: obj.petBodyId,detection: jsonEncode(detectionObj.toJson()),- bodyVectorId: -1,+ bodyVectorId: null,species: obj.cocoClass == 15 ? 1 : 0,score: obj.score,imageHeight: result.decodedImageSize.height,diff --git a/mobile/apps/photos/lib/ui/social/widgets/shared_photos_grid.dart b/mobile/apps/photos/lib/ui/social/widgets/shared_photos_grid.dartindex 545ef7495a..a647b7f03e 100644--- a/mobile/apps/photos/lib/ui/social/widgets/shared_photos_grid.dart+++ b/mobile/apps/photos/lib/ui/social/widgets/shared_photos_grid.dart@@ -28,6 +28,7 @@ class SharedPhotosGrid extends StatefulWidget {/// Called when user taps the +N extra-count badge.final VoidCallback? onExtraCountTap;+/// Prefix used for Hero tags while opening shared photos.final String heroTagPrefix;diff --git a/mobile/apps/photos/lib/utils/ml_util.dart b/mobile/apps/photos/lib/utils/ml_util.dartindex dbb297411c..1a483e8000 100644--- a/mobile/apps/photos/lib/utils/ml_util.dart+++ b/mobile/apps/photos/lib/utils/ml_util.dart@@ -109,7 +109,8 @@ Future<List<FileMLInstruction>> getFilesForMlIndexing() async {final Map<int, int> faceIndexedFileIDs = await mlDataDB.faceIndexedFileIds();final Map<int, int> clipIndexedFileIDs =await mlDataDB.clipIndexedFileWithVersion();- final bool petEnabled = flagService.internalUser && localSettings.petRecognitionEnabled;+ final bool petEnabled =+ flagService.internalUser && localSettings.petRecognitionEnabled;final Map<int, int> petIndexedFileIDs =petEnabled ? await mlDataDB.petIndexedFileIds() : const {};final Set<int> queuedFiledIDs = {};@@ -224,7 +225,8 @@ Future<List<FileMLInstruction>> getOfflineFilesForMlIndexing() async {final Map<int, int> faceIndexedFileIDs = await mlDataDB.faceIndexedFileIds();final Map<int, int> clipIndexedFileIDs =await mlDataDB.clipIndexedFileWithVersion();- final bool petEnabled = flagService.internalUser && localSettings.petRecognitionEnabled;+ final bool petEnabled =+ flagService.internalUser && localSettings.petRecognitionEnabled;final Map<int, int> petIndexedFileIDs =petEnabled ? await mlDataDB.petIndexedFileIds() : const {};final Set<int> queuedFileIDs = {};