]> BookStack Code Mirror - bookstack/blobdiff - app/Auth/User.php
Guest create page: name field autofocus
[bookstack] / app / Auth / User.php
index 4e21832449d5a6ab1068e82e3b136c151bf72f6f..6e66bc808296c4c531568ac516c93412000a07c9 100644 (file)
@@ -80,6 +80,11 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
      */
     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.
      *
@@ -163,7 +168,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
     }
 
     /**
-     * Get all permissions belonging to the current user.
+     * Get all permissions belonging to the current user.
      */
     protected function permissions(): Collection
     {
@@ -233,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;
     }