-
Notifications
You must be signed in to change notification settings - Fork 262
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: reduce number of avatar requests #10486
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Hamza Mahjoubi <hamzamahjoubi221@gmail.com>
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.
Quick review
I broke RecipientBubble 😨, converting to draft |
Signed-off-by: Hamza Mahjoubi <hamzamahjoubi221@gmail.com>
The avatar controller and frontend service are still needed for Recipient bubble (Thread.vue) , because the message object contains only from's avatar ( to, cc, bcc ) still need to be fetched , and assuming that we need them and pre-fetching is counterproductive because we can't assume that all threads are gonna be opened |
Signed-off-by: Hamza Mahjoubi <hamzamahjoubi221@gmail.com>
Signed-off-by: Hamza Mahjoubi <hamzamahjoubi221@gmail.com>
Signed-off-by: Hamza Mahjoubi <hamzamahjoubi221@gmail.com>
// If we are in the API call, we need to fetch the avatar for the sender | ||
if ($mode === 'apiCall') { | ||
foreach ($messages as $message) { | ||
$from = $message->getFrom()->first() ; |
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.
$from = $message->getFrom()->first() ; | |
$from = $message->getFrom()->first(); |
} | ||
|
||
/** | ||
* @param Message[] $messages | ||
* | ||
* @return Message[] | ||
*/ | ||
public function process(Account $account, Mailbox $mailbox, array $messages): array { | ||
public function process(Account $account, Mailbox $mailbox, array $messages, string $mode = 'sync'): array { |
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.
public function process(Account $account, Mailbox $mailbox, array $messages, string $mode = 'sync'): array { | |
public function process(Account $account, Mailbox $mailbox, array $messages, bool $preLoadAvatars = false): array { |
$this->clientFactory = $clientFactory; | ||
$this->imapMapper = $imapMapper; | ||
$this->mapper = $dbMapper; | ||
$this->logger = $logger; | ||
$this->avatarService = $avatarService; | ||
$this->userId = $userId; |
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.
nitpick: I see injection of data as a code smell. The only exception for a valid userId injection is a controller.
Would it be possible to move the transport of the user context (userId) to the method parameters?
How will this handle worst case scenarios? Imagine you load 20 messages and each of them is sent by someone else, and there is no contacts picture so gravatar favicon sources are tapped. These make external HTTP requests that could take several seconds, e.g. when the favicon request times out because the domain does not correspond to a HTTP server. Will this slow down the loading of messages? If so, we have to fine-tune the approach. Let me know, I have some ideas. |
So I did a little benchmarking and here are the results Main
This branch
Doesn't look like a good approach |
Okay, that is what I was afraid of. Then we do it like follows: check the cache for an avatar URL. If it exists, attach it to the recipient. Also attach a false if there is one, it indicates that there is no avatar for the user. This means that the initial loading with empty cache is still done in many requests, but those help us offload the slow fetching into async operations that don't block the main app functionality. For page reloads, mailbox switches, messages of senders seen previously etc we will preload the avatar URLs and save some requests. |
No description provided.