Repository navigation
fix(imap): apply flag changes to large folders on the server - #14328
DerDreschner wants to merge 1 commit into
Conversation
Marking a folder with more than about 10,000 messages as read sent one UID STORE with every UID, unsorted. Dovecot rejects such a long command with BAD, and Horde ignores a rejected STORE, so the database showed the messages as read while they stayed unread on the server. Send the UIDs sorted, so they compress into ranges, and split them at the command length Horde uses for its own FETCH. Log in before reading the capabilities, because the list before login lacks CONDSTORE and with it the longer command length. Regression from 8994221 (JMAP part 2). 5.13 marks a folder as read with a single STORE for all messages and is not affected. Left out: the STORE chunks are not atomic, so if a later chunk fails, the next sync reconciles the flags. Horde still ignores NO/BAD replies to STORE; catching them needs a _store override in HordeImapClient. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: David Dreschner <david.dreschner@nextcloud.com>
ChristophWurst
left a comment
There was a problem hiding this comment.
LGTM — approve.
The sorting + split($capability->cmdlength) fixes the over-long UID STORE, and calling login() first is safe: it's idempotent in Horde (_isAuthenticated guard) and store() would log in anyway. Verified the Horde APIs against vendor (Ids::split(), cmdlength = 8000 with CONDSTORE else 2000) and ran MessageMapperTest locally — the four new tests pass.
Two optional follow-ups, non-blocking:
- The root cause is still open: Horde ignores NO/BAD on STORE, so a rejected chunk is silent until the next sync. A
_storeoverride inHordeImapClientwould catch it — worth a tracking issue linked here. - Would be nice to assert
login()is invoked (e.g.$client->expects($this->once())->method('login')) to lock in the login-before-capability ordering.
On the 1:* question: markAllRead() still does a single STORE 1:* and is untouched, but markFolderAsRead can't just go back to it — since 8994221 the local DB flags are updated per message inside flagMessages(). A 1:* fast path would need a bulk UPDATE on the DB side alongside it to keep local state in sync. Happy to leave that as a separate optimization; this fix correctly covers the general case (large selections, tags, threads), not just mark-all-read.
Assisted by OpenCode:mistral-large-4
|
Sorry, wrong comment got deleted 🙄 Assisted by void |
|
@DerDreschner please share your findings |
|
We can, and it's worth it: in a prototype, Mark all as read on 20k unread messages took 1.3–1.5 s with Why separately: since JMAP part 2, Mark all as read goes through
That's a connector interface change, a new mapper query and different event semantics, which deserves its own review rather than riding along with a regression fix. Why this PR is needed anyway: Assisted by ClaudeCode:claude-opus-5-5 |
Context
Marking a folder with more than about 10k messages as read sent one
UID STOREwith every UID, unsorted. Dovecot rejects the command as too long, and Horde ignores a rejected STORE: the database shows the messages as read, the server keeps them unread.Regression from 8994221 (JMAP part 2), main only; 5.13 uses a single
STORE 1:*and isn't affected.Approach
Left out: the chunks aren't atomic (the next sync reconciles the flags if a later chunk fails), and Horde still ignores NO/BAD on STORE (needs a
_storeoverride inHordeImapClient).Testing
Unit tests for unsorted UIDs as one range, splitting sparse UIDs, empty input and a failing chunk.
Mark 20k messages as read (Dovecot, MariaDB, CLI):
Slightly slower because the server now applies the change and reports the flag updates.
AI assistance
Assisted by ClaudeCode:claude-opus-5-5