Skip to content

Commit

Permalink
perf(ThreadCell): Use realm lazy query instead of iterating through a…
Browse files Browse the repository at this point in the history
…ll messages (#1404)
  • Loading branch information
valentinperignon authored Apr 29, 2024
2 parents 9057a20 + af23624 commit 646a7d4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Mail/Components/ThreadCell/ThreadCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ extension ThreadDensity {
}

struct ThreadCellDataHolder {
static let lastMessageNotFromSentPredicate = NSPredicate(
format: "SUBQUERY(folders, $folder, $folder.role != %@).@count > 0",
FolderRole.sent.rawValue
)
/// Sender of the last message that is not in the Sent folder, otherwise the last message of the thread
let recipientToDisplay: Recipient?

Expand All @@ -49,7 +53,8 @@ struct ThreadCellDataHolder {
let isInWrittenByMeFolder: Bool

init(thread: Thread) {
let lastMessageNotFromSent = thread.messages.last { $0.folder?.role != .sent } ?? thread.messages.last
let lastMessageNotFromSent = thread.messages.filter(Self.lastMessageNotFromSentPredicate).last ?? thread.messages.last

date = thread.date.formatted(.thread(.list))

subject = thread.formattedSubject
Expand Down

0 comments on commit 646a7d4

Please sign in to comment.