mail icon indicating copy to clipboard operation
mail copied to clipboard

perf(imap): FETCH only flags for partial message updates

Open ChristophWurst opened this issue 2 years ago • 4 comments

Fixes https://github.com/nextcloud/mail/issues/8451

ChristophWurst avatar May 04 '23 18:05 ChristophWurst

before:

C: 7 UID FETCH 2726 (FLAGS BODY.PEEK[HEADER])
S: * 1 FETCH (UID 2726 FLAGS (\Seen NonJunk) BODY[HEADER] {8549}
Return-Path: <***@***>
Authentication-Results: ***
Received: ***
DKIM-Signature: ***
X-UI-Sender-Class: ***
Received: from ***
Date: ***
To: ***
From: ***
Reply-To: ***
Subject: ***
Message-ID: ***
X-MA-Provider: ***
X-Data: ***
MIME-Version: ***
Content-Type: ***
X-Provags-ID: ***
Envelope-To: ***
x-tdresult: ***
x-tdcapabilities: ***
X-Spam-Flag: ***
UI-InboundReport: ***

S: )
S: 7 OK UID FETCH completed
>> Command 7 took 0.047 seconds.

after:

C: 7 UID FETCH 2726 (FLAGS)
S: * 1 FETCH (UID 2726 FLAGS (\Seen NonJunk))
S: 7 OK UID FETCH completed
>> Command 7 took 0.0289 seconds.

JohannesGGE avatar Feb 06 '24 14:02 JohannesGGE

something is odd.

341x 55.8 ms ↴ select * from oc_mail_tags where (imap_label = ?) and (user_id = ?) 341x 47.6 ms ↴ insert into oc_mail_message_tags(...) values (?)

from blackfire

ChristophWurst avatar Feb 06 '24 17:02 ChristophWurst

Found the issue. We use the messageID to check and update the tags. Without the header, we don't fetch the messageID anymore.

It could be possible to adjust the update of the tags with an additional join of mail_message_tags and mail_messages to get the uid that is fetched. Could be worth a try.

JohannesGGE avatar Feb 20 '24 10:02 JohannesGGE

The current state fails because the entries in mail_message_tags are stored with the message_id. The message_id is not part of the header and because of that not fetched in the new partial sync. \OCA\Mail\Db\MessageMapper::updateTags tries to diff on message_id and creates a generated message_id because none is found. Because of the mismatch of the message_id in mail_message_tags and mail_messages the partial sync always adds all tags to mail_message_tags (always with auto generated message_id).

It could be an option to join additionally on mail_messages in \OCA\Mail\Db\TagMapper::getAllTagsForMessages. This requires a bit more complex change because \OCA\Mail\Db\MessageMapper::updateTags needs the uid to diff and the matching message_id to create the db entry in mail_message_tags then.

For some reason the initial sync is also broken in this branch and the message_id is generated. I don't understand why, in my understanding only the partial sync is affected by the changes.

JohannesGGE avatar Mar 19 '24 16:03 JohannesGGE