Skip to content

Commit

Permalink
feat: Remove empty address books
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthieu-dgl committed Jan 16, 2025
1 parent 0741f5f commit 1971be5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion MailCore/Cache/ContactManager/ContactManager+DB.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,16 @@ public extension ContactManager {
/// - fetchLimit: limit the query by default to limit memory footprint
/// - Returns: The collection of matching contacts.
func frozenAddressBookContacts(matching string: String, fetchLimit: Int?) -> any Collection<AddressBook> {
var lazyResults = fetchResults(ofType: AddressBook.self) { partial in
let mergedContacts = fetchResults(ofType: MergedContact.self) { partial in
partial
}

let mergedContactIds = Array(mergedContacts.compactMap { $0.remoteAddressBookId })

var lazyResults = fetchResults(ofType: AddressBook.self) { partial in
partial.where { $0.id.in(mergedContactIds) }
}

lazyResults = lazyResults
.filter(Self.searchGroupContactInsensitivePredicate, string, string)
.freeze()
Expand Down

0 comments on commit 1971be5

Please sign in to comment.