Update Forums

Move the work with the cache to the manager.
This commit is contained in:
Visman 2020-10-30 11:45:06 +07:00
parent 7964c9d3ca
commit 614f6c87ae
2 changed files with 23 additions and 22 deletions

View file

@ -27,6 +27,7 @@ class Manager extends ManagerModel
/**
* Инициализация списка разделов
* Обновляет кеш разделов
*/
public function init(Group $group = null): Manager
{
@ -37,25 +38,34 @@ class Manager extends ManagerModel
}
$mark = $this->c->Cache->get('forums_mark');
if (empty($mark)) {
if (true !== $this->c->Cache->set('forums_mark', \time())) {
$mark = \time();
if (true !== $this->c->Cache->set('forums_mark', $mark)) {
throw new RuntimeException('Unable to write value to cache - forums_mark');
}
$list = $this->refresh($group);
$result = [];
} else {
$result = $this->c->Cache->get('forums_' . $gid);
if (
empty($result['time'])
|| $result['time'] < $mark
) {
$list = $this->refresh($group);
} else {
$list = $result['list'];
$result = $this->c->Cache->get("forums_{$gid}");
}
if (
! isset($result['time'], $result['list'])
|| $result['time'] < $mark
) {
$result = [
'time' => $mark,
'list' => $this->refresh($group),
];
if (true !== $this->c->Cache->set("forums_{$gid}", $result)) {
throw new RuntimeException('Unable to write value to cache - forums_' . $gid);
}
}
$this->forumList = $list;
$this->forumList = $result['list'];
return $this;
}

View file

@ -6,7 +6,6 @@ namespace ForkBB\Models\Forum;
use ForkBB\Models\Action;
use ForkBB\Models\Group\Model as Group;
use RuntimeException;
class Refresh extends Action
{
@ -17,7 +16,6 @@ class Refresh extends Action
/**
* Возвращает список доступных разделов для группы
* Обновляет кеш
*/
public function refresh(Group $group = null): array
{
@ -29,6 +27,8 @@ class Refresh extends Action
$read = $group->g_read_board;
}
$this->list = [];
if ('1' == $read) {
$list = [];
$vars = [
@ -53,15 +53,6 @@ class Refresh extends Action
}
}
$result = $this->c->Cache->set('forums_' . $gid, [
'time' => \time(),
'list' => $this->list,
]);
if (true !== $result) {
throw new RuntimeException('Unable to write value to cache - forums_' . $gid);
}
return $this->list;
}