Actually hook up the memoizer for UserRole.

This commit is contained in:
flash 2020-06-05 12:43:04 +00:00
parent e6b69a23e8
commit d60f36f86f

View file

@ -179,13 +179,15 @@ class UserRole implements ArrayAccess, HasRankInterface {
return sprintf(self::QUERY_SELECT, sprintf(self::SELECT, self::TABLE));
}
public static function byId(int $roleId): self {
$object = DB::prepare(
self::byQueryBase() . ' WHERE `role_id` = :role'
) ->bind('role', $roleId)
->fetchObject(self::class);
if(!$object)
throw new UserRoleNotFoundException;
return $object;
return self::memoizer()->find($roleId, function() use ($roleId) {
$object = DB::prepare(
self::byQueryBase() . ' WHERE `role_id` = :role'
) ->bind('role', $roleId)
->fetchObject(self::class);
if(!$object)
throw new UserRoleNotFoundException;
return $object;
});
}
public static function byDefault(): self {
return self::byId(self::DEFAULT);