]> BookStack Code Mirror - bookstack/blobdiff - app/Auth/User.php
Guest create page: name field autofocus
[bookstack] / app / Auth / User.php
index b7f88b59003ff80457ccca05e2dab53c16c30eea..6e66bc808296c4c531568ac516c93412000a07c9 100644 (file)
@@ -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 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;
     }