Skip to content

Commit

Permalink
fix(avatars): Reduce cache time in fallback cases (remote was offline)
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Mar 18, 2024
1 parent dd0ce1a commit e0c23ee
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 e0c23ee

Please sign in to comment.