Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

fix: remove updatedAt from [PersonEntity], better hash logic

Prateek Sunal7719c4604ed2
diff --git a/mobile/lib/models/ml/face/person.dart b/mobile/lib/models/ml/face/person.dart
index 9d7d437c77..ad7d20ef6d 100644
--- a/mobile/lib/models/ml/face/person.dart
+++ b/mobile/lib/models/ml/face/person.dart
@@ -6,11 +6,9 @@ import "package:flutter/foundation.dart";
class PersonEntity {
final String remoteID;
final PersonData data;
- final DateTime updatedAt;
PersonEntity(
this.remoteID,
this.data,
- this.updatedAt,
);
// copyWith
@@ -22,7 +20,6 @@ class PersonEntity {
return PersonEntity(
remoteID ?? this.remoteID,
data ?? this.data,
- updatedAt ?? this.updatedAt,
);
}
}
diff --git a/mobile/lib/services/album_home_widget_service.dart b/mobile/lib/services/album_home_widget_service.dart
index c380bd221e..2a5d422d14 100644
--- a/mobile/lib/services/album_home_widget_service.dart
+++ b/mobile/lib/services/album_home_widget_service.dart
@@ -184,7 +184,7 @@ class AlbumHomeWidgetService {
for (final albumId in albumIds) {
final collection = CollectionsService.instance.getCollectionByID(albumId);
if (collection != null) {
- updationTimestamps += "${collection.updationTime.toString()}_";
+ updationTimestamps += "$albumId:${collection.updationTime.toString()}_";
}
}
diff --git a/mobile/lib/services/entity_service.dart b/mobile/lib/services/entity_service.dart
index 2986a33ef5..410b4cb7a9 100644
--- a/mobile/lib/services/entity_service.dart
+++ b/mobile/lib/services/entity_service.dart
@@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:convert';
import 'dart:math';
+import "package:crypto/crypto.dart";
import "package:ente_crypto/ente_crypto.dart";
import 'package:flutter/foundation.dart';
import 'package:logging/logging.dart';
@@ -219,4 +220,19 @@ class EntityService {
rethrow;
}
}
+
+ Future<String> getHashForIds(List<String> personIds) async {
+ String preHash = "";
+
+ for (final id in personIds) {
+ final entity = await getEntity(EntityType.person, id);
+
+ if (entity != null) {
+ preHash = "$id:${entity.updatedAt}_";
+ }
+ }
+
+ final hash = md5.convert(utf8.encode(preHash)).toString().substring(0, 10);
+ return hash;
+ }
}
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.dart
index 407cc1b0f1..dd1283b9ac 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
@@ -78,7 +78,6 @@ class PersonService {
(e) => PersonEntity(
e.id,
PersonData.fromJson(json.decode(e.data)),
- DateTime.fromMicrosecondsSinceEpoch(e.updatedAt),
),
)
.toList();
@@ -92,7 +91,6 @@ class PersonService {
return PersonEntity(
e.id,
PersonData.fromJson(json.decode(e.data)),
- DateTime.fromMicrosecondsSinceEpoch(e.updatedAt),
);
});
}
@@ -104,7 +102,6 @@ class PersonService {
final person = PersonEntity(
e.id,
PersonData.fromJson(json.decode(e.data)),
- DateTime.fromMicrosecondsSinceEpoch(e.updatedAt),
);
map[person.remoteID] = person;
}
@@ -222,11 +219,7 @@ class PersonService {
await resetEmailToPartialPersonDataCache();
}
memoriesCacheService.queueUpdateCache();
- return PersonEntity(
- result.id,
- data,
- DateTime.fromMicrosecondsSinceEpoch(result.updatedAt),
- );
+ return PersonEntity(result.id, data);
}
Future<void> removeClusterToPerson({
@@ -302,11 +295,8 @@ class PersonService {
if (entity == null) {
return;
}
- final PersonEntity justName = PersonEntity(
- personID,
- PersonData(name: entity.data.name),
- entity.updatedAt,
- );
+ final PersonEntity justName =
+ PersonEntity(personID, PersonData(name: entity.data.name));
await entityService.addOrUpdate(
EntityType.cgroup,
justName.data.toJson(),
diff --git a/mobile/lib/services/people_home_widget_service.dart b/mobile/lib/services/people_home_widget_service.dart
index 61b23b46af..a44a70159b 100644
--- a/mobile/lib/services/people_home_widget_service.dart
+++ b/mobile/lib/services/people_home_widget_service.dart
@@ -1,8 +1,6 @@
-import "dart:convert";
import "dart:math";
import "package:collection/collection.dart";
-import "package:crypto/crypto.dart";
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:logging/logging.dart';
@@ -235,23 +233,7 @@ class PeopleHomeWidgetService {
}
Future<String> _calculateHash(List<String> peopleIds) async {
- String updationTimestamps = "";
- // Check if selected people exist
- for (final id in peopleIds) {
- try {
- final person = await PersonService.instance.getPerson(id);
- if (person != null) {
- updationTimestamps += "${person.updatedAt.toString()}_";
- }
- } catch (e) {
- _logger.warning("Error looking up people: $e");
- }
- }
- final hash = md5
- .convert(utf8.encode(updationTimestamps))
- .toString()
- .substring(0, 10);
- return hash;
+ return await entityService.getHashForIds(peopleIds);
}
Future<bool> _hasAnyBlockers() async {