добавлено кэширование класса Юзер
This commit is contained in:
1 parent
a4d65fa44d
commit
1412003d5e
2 files changed
+23
-9
No files matched your search
@@ -1,4 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Версия сервиса
|
||||
*/
|
||||
define('VERSION', '1.0.0');
|
||||
|
||||
/**
|
||||
* Путь до корня проекта
|
||||
*/
|
||||
@@ -34,3 +40,7 @@
|
||||
*/
|
||||
define('USER_ONLINE_TIME', 60 * 5);
|
||||
|
||||
/**
|
||||
* Время жизни кэша
|
||||
*/
|
||||
define('CACHE_TTL', 3600);
|
||||
@@ -55,6 +55,7 @@
|
||||
if (empty($id)) {
|
||||
throw new CoreException('Передан некорректный идентификатор пользователя');
|
||||
}
|
||||
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
@@ -65,8 +66,15 @@
|
||||
*/
|
||||
public function getAllUserData(): ?array
|
||||
{
|
||||
$result = (DB::getInstance())->getItem(self::TABLE, ['id' => $this->id]);
|
||||
if ($result) {
|
||||
$cacheId = md5('User_getAllUserData_' . $this->id);
|
||||
if(Cache::check($cacheId)) {
|
||||
$result = Cache::get($cacheId);
|
||||
} else {
|
||||
$result = (DB::getInstance())->getItem(self::TABLE, ['id' => $this->id]);
|
||||
Cache::set($cacheId, $result);
|
||||
}
|
||||
|
||||
if (!empty($result)) {
|
||||
return $result;
|
||||
} else {
|
||||
return null;
|
||||
@@ -360,14 +368,10 @@
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isAdmin(): bool
|
||||
public function isAdmin(): bool
|
||||
{
|
||||
if (self::isUser()) {
|
||||
if (self::getFields(self::$id)['access_level'] == 'admin') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if ($this->getAllUserData()['access_level'] == self::ACCESS_ADMIN) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user