Repository navigation
fix(sync): don't return the mailbox as new messages from the initial sync #13823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,4 +133,62 @@ public function testSyncMailboxReturnsFolderStats(): void { | |
|
|
||
| $this->assertEquals($expectedResponse, $response); | ||
| } | ||
|
|
||
| public function testInitialSyncReturnsNoMessages(): void { | ||
| $account = $this->createMock(Account::class); | ||
| $account->method('getUserId')->willReturn('user'); | ||
| $mailbox = new Mailbox(); | ||
| $mailbox->setMessages(33000); | ||
| $mailbox->setUnseen(24000); | ||
| $this->messageConnector->expects($this->once()) | ||
| ->method('syncMailbox') | ||
| ->willReturn(new \OCA\Mail\Protocol\SyncResult()); | ||
| // The client loads the first page itself, so the cache is not read | ||
| $this->messageMapper->expects($this->never()) | ||
| ->method('findAllIds'); | ||
| $this->messageMapper->expects($this->never()) | ||
| ->method('findNewIds'); | ||
| $this->messageMapper->expects($this->never()) | ||
| ->method('findByMailboxAndIds'); | ||
|
|
||
| $response = $this->syncService->syncMailbox( | ||
| $account, | ||
| $mailbox, | ||
| 0, | ||
| false, | ||
| null, | ||
| [] | ||
| ); | ||
|
|
||
| $this->assertEquals(new Response([], [], [], new MailboxStats(33000, 24000, null)), $response); | ||
| } | ||
|
|
||
| public function testPartialSyncReadsTheCache(): void { | ||
| $account = $this->createMock(Account::class); | ||
| $account->method('getUserId')->willReturn('user'); | ||
| $mailbox = new Mailbox(); | ||
| $mailbox->setMessages(3); | ||
| $mailbox->setUnseen(1); | ||
| $mailbox->setSyncNewToken('token'); | ||
| $mailbox->setSyncChangedToken('token'); | ||
| $mailbox->setSyncVanishedToken('token'); | ||
| $this->messageConnector->expects($this->once()) | ||
| ->method('syncMailbox') | ||
| ->willReturn(new \OCA\Mail\Protocol\SyncResult()); | ||
| $this->messageMapper->expects($this->once()) | ||
| ->method('findNewIds') | ||
| ->with($mailbox, [1, 2], null, 'DESC') | ||
| ->willReturn([3]); | ||
| $this->messageMapper->method('findByMailboxAndIds') | ||
| ->willReturn([]); | ||
|
|
||
| $this->syncService->syncMailbox( | ||
| $account, | ||
| $mailbox, | ||
| 0, | ||
| true, | ||
| null, | ||
| [1, 2] | ||
| ); | ||
| } | ||
|
Comment on lines
+166
to
+193
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: nextcloud/mail
Length of output: 8056
Reconcile retained IDs during initialization.
When
init: trueincludes known IDs, derivechangedMessagesandvanishedMessagesfor those IDs before returning. KeepnewMessagesempty for initialization. Reuse the existing changed/vanished-ID queries, but do not run the initialization path through the fullnewMessageslookup orpreviewEnhancer->process(). This updates stale flags and removes deleted envelopes without restoring the memory-heavy full-mailbox response.