From 401bcee258713b911cd67aa6dc832e4eff25deb4 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Fri, 16 Aug 2024 09:14:46 -0500 Subject: jmap: refactor thread fetching Refactor JMAP thread fetching to occur in a single request. We use a result reference method call on Email/get to fetch the message info for each message in a thread. Previously, we checked the cache and only fetched information for messages we didn't already have. This results in two requests and is typically slower for most contexts. Also, in most cases if we are fetching an email we don't already have it's because we also need to fetch the entire thread. The only case this wouldn't happen is if we get a new email in a thread. We can optimize this by fetching message info for created messages in the push method at a later time. Signed-off-by: Tim Culverhouse Acked-by: Robin Jarry --- worker/jmap/fetch.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'worker/jmap/fetch.go') diff --git a/worker/jmap/fetch.go b/worker/jmap/fetch.go index bbef1bb5..07579b99 100644 --- a/worker/jmap/fetch.go +++ b/worker/jmap/fetch.go @@ -44,14 +44,20 @@ func (w *JMAPWorker) handleFetchMessageHeaders(msg *types.FetchMessageHeaders) e } jid := jmap.ID(id) m, err := w.cache.GetEmail(jid) - if err == nil { - currentEmails = append(currentEmails, m) - } else { + if err != nil { + // Message wasn't in cache; fetch it emailIdsToFetch = append(emailIdsToFetch, jid) + continue } + currentEmails = append(currentEmails, m) + // Get the UI updated immediately + w.w.PostMessage(&types.MessageInfo{ + Message: types.RespondTo(msg), + Info: w.translateMsgInfo(m), + }, nil) } - if len(emailIdsToFetch) != 0 { + if len(emailIdsToFetch) > 0 { var req jmap.Request req.Invoke(&email.Get{ -- cgit