Skip to content

Commit 48ebeee

Browse files
committed
feat: Remove empty address books
1 parent d02797f commit 48ebeee

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

MailCore/Cache/ContactManager/ContactManager+DB.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,16 @@ public extension ContactManager {
127127
/// - fetchLimit: limit the query by default to limit memory footprint
128128
/// - Returns: The collection of matching contacts.
129129
func frozenAddressBookContacts(matching string: String, fetchLimit: Int?) -> any Collection<AddressBook> {
130-
var lazyResults = fetchResults(ofType: AddressBook.self) { partial in
130+
let mergedContacts = fetchResults(ofType: MergedContact.self) { partial in
131131
partial
132132
}
133+
134+
let mergedContactIds = Array(mergedContacts.compactMap { $0.remoteAddressBookId })
135+
136+
var lazyResults = fetchResults(ofType: AddressBook.self) { partial in
137+
partial.where { $0.id.in(mergedContactIds) }
138+
}
139+
133140
lazyResults = lazyResults
134141
.filter(Self.searchGroupContactInsensitivePredicate, string, string)
135142
.freeze()

0 commit comments

Comments
 (0)