Skip to content
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

perf: don't retransmit unchanged threads #10751

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
[
'name' => 'messages#getThread',
'url' => '/api/messages/{id}/thread',
'verb' => 'GET'
'verb' => 'POST'
],
[
'name' => 'messages#setFlags',
Expand Down
14 changes: 11 additions & 3 deletions lib/Controller/MessagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,13 @@
* @NoAdminRequired
* @NoCSRFRequired
*
* @param int $id
* @param int[] $knownIds Known database ids of envelopes
*
* @return JSONResponse
* @throws ClientException
*/
#[TrapError]
public function getThread(int $id): JSONResponse {
public function getThread(int $id, array $knownIds): JSONResponse {
try {
$message = $this->mailManager->getMessage($this->currentUserId, $id);
$mailbox = $this->mailManager->getMailbox($this->currentUserId, $message->getMailboxId());
Expand All @@ -337,7 +337,15 @@
return new JSONResponse([], Http::STATUS_NOT_FOUND);
}

return new JSONResponse($this->mailManager->getThread($account, $message->getThreadRootId()));
$thread = $this->mailManager->getThread($account, $message->getThreadRootId());
foreach ($thread as $envelope) {
if (!in_array($envelope->getId(), $knownIds)) {

Check warning on line 342 in lib/Controller/MessagesController.php

View check run for this annotation

Codecov / codecov/patch

lib/Controller/MessagesController.php#L340-L342

Added lines #L340 - L342 were not covered by tests
// Thread changed -> send it
return new JSONResponse($thread);

Check warning on line 344 in lib/Controller/MessagesController.php

View check run for this annotation

Codecov / codecov/patch

lib/Controller/MessagesController.php#L344

Added line #L344 was not covered by tests
}
}

return new JSONResponse([], Http::STATUS_NO_CONTENT);

Check warning on line 348 in lib/Controller/MessagesController.php

View check run for this annotation

Codecov / codecov/patch

lib/Controller/MessagesController.php#L348

Added line #L348 was not covered by tests
}

/**
Expand Down
12 changes: 10 additions & 2 deletions src/service/MessageService.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,19 @@ export function fetchEnvelopes(accountId, mailboxId, query, cursor, limit) {
throw convertAxiosError(error)
})
}
export const fetchThread = async (id) => {
export const fetchThread = async (id, knownIds) => {
const url = generateUrl('apps/mail/api/messages/{id}/thread', {
id,
})
const resp = await axios.get(url)
const resp = await axios.post(url, {
knownIds,
})

// Thread is up to date
if (resp.status === 204) {
return []
}

return resp.data
}

Expand Down
16 changes: 10 additions & 6 deletions src/store/mainStore/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1190,12 +1190,16 @@ export default function mainStoreActions() {
},
async fetchThread(id) {
return handleHttpAuthErrors(async () => {
const thread = await fetchThread(id)
this.addEnvelopeThreadMutation({
id,
thread,
})
return thread
const knownDatabaseIds = this.envelopes[id]?.thread ?? []
const thread = await fetchThread(id, knownDatabaseIds)
if (thread.length > 0) {
this.addEnvelopeThreadMutation({
id,
thread,
})
}

return this.getEnvelopeThread(id)
})
},
async fetchMessage(id) {
Expand Down
Loading