mirror of
https://github.com/flarum/framework.git
synced 2024-12-12 14:13:37 +08:00
PERF: cache the results of User::hasPermssion()
This commit is contained in:
parent
372a159521
commit
5ae7bfefaa
|
@ -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];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user