Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Minor perf optimization

ashilkn85d50890a636
diff --git a/mobile/lib/services/search_service.dart b/mobile/lib/services/search_service.dart
index 4a0443db7d..a30b2109b9 100644
--- a/mobile/lib/services/search_service.dart
+++ b/mobile/lib/services/search_service.dart
@@ -1361,7 +1361,7 @@ class SearchService {
}
final relevantContactEmails =
- UserService.instance.getRelevantContacts().map((e) => e.email).toSet();
+ UserService.instance.getEmailIDsOfRelevantContacts();
final emailsInRelContEmailsAndNotInExistingEmails =
relevantContactEmails.difference(existingEmails);
@@ -1423,10 +1423,8 @@ class SearchService {
}
}
- final allRelevantEmails = UserService.instance
- .getRelevantContacts()
- .map((e) => e.email)
- .toSet();
+ final allRelevantEmails =
+ UserService.instance.getEmailIDsOfRelevantContacts();
int? buffer = limit != null ? limit - peopleCount : null;
final emailsWithNoSharedFiles =
diff --git a/mobile/lib/services/user_service.dart b/mobile/lib/services/user_service.dart
index fbe46cb459..60b2ad04f0 100644
--- a/mobile/lib/services/user_service.dart
+++ b/mobile/lib/services/user_service.dart
@@ -1374,4 +1374,82 @@ class UserService {
return relevantUsers;
}
+
+ /// Returns emails of Users that are relevant to the account owner.
+ /// Note: "User" refers to the account owner in the points below.
+ /// This includes:
+ /// - Collaborators and viewers of collections owned by user
+ /// - Owners of collections shared to user.
+ /// - All collaborators of collections in which user is a collaborator or
+ /// a viewer.
+ /// - All family members of user.
+ /// - All contacts linked to a person.
+ Set<String> getEmailIDsOfRelevantContacts() {
+ final emailIDs = <String>{};
+
+ final int ownerID = Configuration.instance.getUserID()!;
+ final String ownerEmail = Configuration.instance.getEmail()!;
+
+ for (final c in CollectionsService.instance.getActiveCollections()) {
+ // Add collaborators and viewers of collections owned by user
+ if (c.owner?.id == ownerID) {
+ for (final User? u in c.sharees ?? []) {
+ if (u != null && u.id != null && u.email.isNotEmpty) {
+ if (!emailIDs.contains(u.email)) {
+ emailIDs.add(u.email);
+ }
+ }
+ }
+ } else if (c.owner?.id != null && c.owner!.email.isNotEmpty) {
+ // Add owners of collections shared with user
+ if (!emailIDs.contains(c.owner!.email)) {
+ emailIDs.add(c.owner!.email);
+ }
+ // Add collaborators of collections shared with user where user is a
+ // viewer or a collaborator
+ for (final User? u in c.sharees ?? []) {
+ if (u != null &&
+ u.id != null &&
+ u.email.isNotEmpty &&
+ u.email == ownerEmail &&
+ (u.isCollaborator || u.isViewer)) {
+ for (final User? u in c.sharees ?? []) {
+ if (u != null &&
+ u.id != null &&
+ u.email.isNotEmpty &&
+ u.isCollaborator) {
+ if (!emailIDs.contains(u.email)) {
+ emailIDs.add(u.email);
+ }
+ }
+ }
+ break;
+ }
+ }
+ }
+ }
+
+ // Add user's family members
+ final cachedUserDetails = getCachedUserDetails();
+ if (cachedUserDetails?.familyData?.members?.isNotEmpty ?? false) {
+ for (final member in cachedUserDetails!.familyData!.members!) {
+ if (!emailIDs.contains(member.email)) {
+ emailIDs.add(member.email);
+ }
+ }
+ }
+
+ // Add contacts linked to people
+ final cachedEmailToPartialPersonData =
+ PersonService.instance.emailToPartialPersonDataMapCache;
+ for (final email in cachedEmailToPartialPersonData.keys) {
+ if (!emailIDs.contains(email)) {
+ emailIDs.add(email);
+ }
+ }
+
+ emailIDs.remove(ownerEmail);
+
+ return emailIDs;
+ }
}