Update BanList
Move the work with the cache to the model.
This commit is contained in:
parent
97de25a05f
commit
5f6e3b99c5
2 changed files with 16 additions and 20 deletions
|
@ -14,7 +14,7 @@ class Load extends Method
|
|||
* Загружает список банов из БД
|
||||
* Создает кеш
|
||||
*/
|
||||
public function load(): BanList
|
||||
public function load(): array
|
||||
{
|
||||
$userList = [];
|
||||
$emailList = [];
|
||||
|
@ -76,21 +76,12 @@ class Load extends Method
|
|||
'expire' => $expire,
|
||||
];
|
||||
}
|
||||
$this->model->banList = $banList;
|
||||
$this->model->userList = $userList;
|
||||
$this->model->emailList = $emailList;
|
||||
$this->model->ipList = $ipList;
|
||||
$result = $this->c->Cache->set('banlist', [
|
||||
|
||||
return [
|
||||
'banList' => $banList,
|
||||
'userList' => $userList,
|
||||
'emailList' => $emailList,
|
||||
'ipList' => $ipList,
|
||||
]);
|
||||
|
||||
if (true !== $result) {
|
||||
throw new RuntimeException('Unable to write value to cache - banlist');
|
||||
}
|
||||
|
||||
return $this->model;
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace ForkBB\Models\BanList;
|
||||
|
||||
use ForkBB\Models\Model as ParentModel;
|
||||
use RuntimeException;
|
||||
|
||||
class Model extends ParentModel
|
||||
{
|
||||
|
@ -15,15 +16,19 @@ class Model extends ParentModel
|
|||
{
|
||||
$list = $this->c->Cache->get('banlist');
|
||||
|
||||
if (isset($list['banList'], $list['userList'], $list['emailList'], $list['ipList'])) {
|
||||
$this->banList = $list['banList'];
|
||||
$this->userList = $list['userList'];
|
||||
$this->emailList = $list['emailList'];
|
||||
$this->ipList = $list['ipList'];
|
||||
} else {
|
||||
$this->load();
|
||||
if (! isset($list['banList'], $list['userList'], $list['emailList'], $list['ipList'])) {
|
||||
$list = $this->load();
|
||||
|
||||
if (true !== $this->c->Cache->set('banlist', $list)) {
|
||||
throw new RuntimeException('Unable to write value to cache - banlist');
|
||||
}
|
||||
}
|
||||
|
||||
$this->banList = $list['banList'];
|
||||
$this->userList = $list['userList'];
|
||||
$this->emailList = $list['emailList'];
|
||||
$this->ipList = $list['ipList'];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue