Skip to content

Commit

Permalink
Merge pull request #11842 from nextcloud/bugfix/noid/reduce-cache-tim…
Browse files Browse the repository at this point in the history
…e-for-fallback-icons

fix(avatars): Reduce cache time in fallback cases (remote was offline)
  • Loading branch information
nickvergessen authored Mar 18, 2024
2 parents dd0ce1a + e0c23ee commit 9f6332a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/Controller/AvatarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,23 @@ public function emojiAvatar(string $emoji, ?string $color): DataResponse {
#[AllowWithoutParticipantWhenPendingInvitation]
#[RequireParticipantOrLoggedInAndListedConversation]
public function getAvatar(bool $darkTheme = false): FileDisplayResponse {
// Cache for 1 day
$cacheDuration = 60 * 60 * 24;
if ($this->room->getRemoteServer() !== '') {
/** @var \OCA\Talk\Federation\Proxy\TalkV1\Controller\AvatarController $proxy */
$proxy = \OCP\Server::get(\OCA\Talk\Federation\Proxy\TalkV1\Controller\AvatarController::class);
try {
return $proxy->getAvatar($this->room, $this->participant, $this->invitation, $darkTheme);
} catch (CannotReachRemoteException) {
// Falling back to a local "globe" avatar for indicating the federation
// Cache for 15 minutes only
$cacheDuration = 15 * 60;
}
}
$file = $this->avatarService->getAvatar($this->getRoom(), $this->userSession->getUser(), $darkTheme);

$response = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => $file->getMimeType()]);
// Cache for 1 day
$response->cacheFor(60 * 60 * 24, false, true);
$response->cacheFor($cacheDuration, false, true);
return $response;
}

Expand Down Expand Up @@ -277,7 +280,7 @@ protected function getPlaceholderResponse(bool $darkTheme): FileDisplayResponse
Http::STATUS_OK,
['Content-Type' => $file->getMimeType()],
);
$response->cacheFor(60 * 60 * 24, false, true);
$response->cacheFor(60 * 15, false, true);
return $response;

}
Expand Down

0 comments on commit 9f6332a

Please sign in to comment.