Skip to content

Commit

Permalink
fixup! perf: reduce number of avatar requests
Browse files Browse the repository at this point in the history
Signed-off-by: Hamza Mahjoubi <hamzamahjoubi221@gmail.com>
  • Loading branch information
hamza221 committed Dec 13, 2024
1 parent f3abc06 commit 3a3867b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/IMAP/PreviewEnhancer.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ public function process(Account $account, Mailbox $mailbox, array $messages): ar
$needAnalyze = array_reduce($messages, function (array $carry, Message $message) {

Check warning on line 64 in lib/IMAP/PreviewEnhancer.php

View check run for this annotation

Codecov / codecov/patch

lib/IMAP/PreviewEnhancer.php#L64

Added line #L64 was not covered by tests
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);

Check failure on line 69 in lib/IMAP/PreviewEnhancer.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

PossiblyNullArgument

lib/IMAP/PreviewEnhancer.php:69:48: PossiblyNullArgument: Argument 1 of OCA\Mail\Service\AvatarService::getAvatar cannot be null, possibly null value provided (see https://psalm.dev/078)
$message->setAvatar($avatar);

Check warning on line 70 in lib/IMAP/PreviewEnhancer.php

View check run for this annotation

Codecov / codecov/patch

lib/IMAP/PreviewEnhancer.php#L67-L70

Added lines #L67 - L70 were not covered by tests
}
return $carry;
Expand Down Expand Up @@ -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);

Check failure on line 118 in lib/IMAP/PreviewEnhancer.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

PossiblyNullArgument

lib/IMAP/PreviewEnhancer.php:118:47: PossiblyNullArgument: Argument 1 of OCA\Mail\Service\AvatarService::getAvatar cannot be null, possibly null value provided (see https://psalm.dev/078)

Check failure on line 118 in lib/IMAP/PreviewEnhancer.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

PossiblyNullReference

lib/IMAP/PreviewEnhancer.php:118:77: PossiblyNullReference: Cannot call method getEmail on possibly null value (see https://psalm.dev/083)
$message->setAvatar($avatar);

Check warning on line 119 in lib/IMAP/PreviewEnhancer.php

View check run for this annotation

Codecov / codecov/patch

lib/IMAP/PreviewEnhancer.php#L116-L119

Added lines #L116 - L119 were not covered by tests

Expand Down

0 comments on commit 3a3867b

Please sign in to comment.