From 3a3867b8dd5e72c15a512e23b857ed1993bd8e0b Mon Sep 17 00:00:00 2001 From: Hamza Mahjoubi Date: Fri, 13 Dec 2024 17:04:49 +0700 Subject: [PATCH] fixup! perf: reduce number of avatar requests Signed-off-by: Hamza Mahjoubi --- lib/IMAP/PreviewEnhancer.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/IMAP/PreviewEnhancer.php b/lib/IMAP/PreviewEnhancer.php index a31e48406b..978960973c 100644 --- a/lib/IMAP/PreviewEnhancer.php +++ b/lib/IMAP/PreviewEnhancer.php @@ -64,8 +64,9 @@ public function process(Account $account, Mailbox $mailbox, array $messages): ar $needAnalyze = array_reduce($messages, function (array $carry, Message $message) { if ($message->getStructureAnalyzed()) { // Try fetching the avatar if it's not set - if ($message->getAvatar() === null && $message->getFrom()->first() !== null) { - $avatar = $this->avatarService->getAvatar($message->getFrom()->first()->getEmail(), $this->userId); + $from = $message->getFrom()->first() ; + if ($message->getAvatar() === null && $from !== null && $this->userId !== null) { + $avatar = $this->avatarService->getAvatar($from->getEmail(), $this->userId); $message->setAvatar($avatar); } return $carry; @@ -112,7 +113,8 @@ public function process(Account $account, Mailbox $mailbox, array $messages): ar $message->setEncrypted($structureData->isEncrypted()); $message->setMentionsMe($structureData->getMentionsMe()); - if ($message->getFrom()->first() !== null) { + $from = $message->getFrom()->first() ; + if ($message->getAvatar() === null && $from !== null && $this->userId !== null) { $avatar = $this->avatarService->getAvatar($message->getFrom()->first()->getEmail(), $this->userId); $message->setAvatar($avatar);