[mob][photos] Minor perf optimization

This commit is contained in:
ashilkn
2025-02-03 14:33:03 +05:30
parent 1201cfc42d
commit 85d50890a6
2 changed files with 81 additions and 5 deletions

View File

@@ -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 =

View File

@@ -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;
}
}