mirror of
https://github.com/flarum/core.git
synced 2025-07-23 01:31:40 +02:00
PERF: cache the results of User::hasPermssion()
This commit is contained in:
@@ -60,6 +60,13 @@ class User extends Model
|
|||||||
'notification_read_time'
|
'notification_read_time'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An cache of permissions, and whether or not this user has them.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $hasPermission = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The hasher with which to hash passwords.
|
* The hasher with which to hash passwords.
|
||||||
*
|
*
|
||||||
@@ -319,7 +326,11 @@ class User extends Model
|
|||||||
$this->setRelation('permissions', $this->permissions()->get());
|
$this->setRelation('permissions', $this->permissions()->get());
|
||||||
}
|
}
|
||||||
|
|
||||||
return (bool) $this->permissions->contains('permission', $permission);
|
if (! isset($this->hasPermissions[$permission])) {
|
||||||
|
$this->hasPermission[$permission] = (bool) $this->permissions->contains('permission', $permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->hasPermission[$permission];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user