X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/c6ad16dba657c82512ae495a4a38b99b8cfa9eeb..refs/pull/3918/head:/app/Auth/User.php diff --git a/app/Auth/User.php b/app/Auth/User.php index b7f88b590..6e66bc808 100644 --- a/app/Auth/User.php +++ b/app/Auth/User.php @@ -77,17 +77,20 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon /** * This holds the user's permissions when loaded. - * - * @var ?Collection */ - protected $permissions; + protected ?Collection $permissions; + + /** + * This holds the user's avatar URL when loaded to prevent re-calculating within the same request. + */ + protected string $avatarUrl = ''; /** * This holds the default user when loaded. * * @var null|User */ - protected static $defaultUser = null; + protected static ?User $defaultUser = null; /** * Returns the default public user. @@ -165,7 +168,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon } /** - * Get all permissions belonging to a the current user. + * Get all permissions belonging to the current user. */ protected function permissions(): Collection { @@ -235,12 +238,18 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon return $default; } + if (!empty($this->avatarUrl)) { + return $this->avatarUrl; + } + try { $avatar = $this->avatar ? url($this->avatar->getThumb($size, $size, false)) : $default; } catch (Exception $err) { $avatar = $default; } + $this->avatarUrl = $avatar; + return $avatar; }