π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob] Minor refactor
Neeraj Guptabba975e6b61d
diff --git a/mobile/lib/services/entity_service.dart b/mobile/lib/services/entity_service.dartindex b8b84406a9..ae2a027061 100644--- a/mobile/lib/services/entity_service.dart+++ b/mobile/lib/services/entity_service.dart@@ -100,15 +100,17 @@ class EntityService {}}- Future<void> syncEntity(EntityType type) async {+ Future<int> syncEntity(EntityType type) async {try {- await _remoteToLocalSync(type);+ return _remoteToLocalSync(type);} catch (e) {_logger.severe("Failed to sync entities", e);+ return -1;}}- Future<void> _remoteToLocalSync(EntityType type) async {+ Future<int> _remoteToLocalSync(EntityType type,+ {int prevFetchCount = 0}) async {final int lastSyncTime =_prefs.getInt(_getEntityLastSyncTimePrefix(type)) ?? 0;final List<EntityData> result = await _gateway.getDiff(@@ -117,7 +119,7 @@ class EntityService {limit: fetchLimit,);if (result.isEmpty) {- return;+ return prevFetchCount;}final bool hasMoreItems = result.length == fetchLimit;_logger.info("${result.length} entries of type $type fetched");@@ -161,6 +163,7 @@ class EntityService {);} catch (e, s) {_logger.severe("Failed to decrypted data for key $type", e, s);+ rethrow;}}if (entities.isNotEmpty) {@@ -170,8 +173,10 @@ class EntityService {await _prefs.setInt(_getEntityLastSyncTimePrefix(type), maxSyncTime);if (hasMoreItems) {_logger.info("Diff limit reached, pulling again");- await _remoteToLocalSync(type);+ await _remoteToLocalSync(type,+ prevFetchCount: prevFetchCount + result.length);}+ return prevFetchCount + result.length;}Future<Uint8List> getOrCreateEntityKey(EntityType type) async {diff --git a/mobile/lib/services/machine_learning/face_ml/person/person_service.dart b/mobile/lib/services/machine_learning/face_ml/person/person_service.dartindex 31ccb54960..eb79e2e553 100644--- a/mobile/lib/services/machine_learning/face_ml/person/person_service.dart+++ b/mobile/lib/services/machine_learning/face_ml/person/person_service.dart@@ -252,8 +252,13 @@ class PersonService {}Future<void> fetchRemoteClusterFeedback() async {- await entityService.syncEntities();+ await entityService.syncEntity(EntityType.cgroup);final entities = await entityService.getEntities(EntityType.cgroup);+ // todo: (neerajg) perf change, this can be expensive to do on every sync+ // especially when we have a lot of people. We should only do this when the+ // last sync time is updated for cgroup entity type. To avoid partial update,+ // we need to maintain a lastSyncTime value whenever this data is processed+ // and stored in the db.entities.sort((a, b) => a.updatedAt.compareTo(b.updatedAt));final Map<String, String> faceIdToClusterID = {};final Map<String, String> clusterToPersonID = {};@@ -286,7 +291,6 @@ class PersonService {);}}-logger.info("Storing feedback for ${faceIdToClusterID.length} faces");await faceMLDataDB.updateFaceIdToClusterId(faceIdToClusterID);await faceMLDataDB.bulkAssignClusterToPersonID(clusterToPersonID);