remove room list cache

This commit is contained in:
ghost 2023-12-11 16:15:34 +02:00
parent 3d5af479de
commit d48a0f5683

View File

@ -53,78 +53,54 @@ class RoomController extends AbstractController
$this->getParameter('app.kevacoin.password') $this->getParameter('app.kevacoin.password')
); );
// Connect memcached
$memcached = new \Memcached();
$memcached->addServer(
$this->getParameter('app.memcached.host'),
$this->getParameter('app.memcached.port')
);
$memory = md5(
sprintf(
'%s.RoomController::list:rooms',
__DIR__
),
);
// Get room list // Get room list
$list = []; $list = [];
if (!$list = $memcached->get($memory)) foreach ((array) $client->kevaListNamespaces() as $value)
{ {
foreach ((array) $client->kevaListNamespaces() as $value) // Calculate room totals
$total = 0;
foreach ((array) $client->kevaFilter($value['namespaceId']) as $post)
{ {
// Calculate room totals // Skip values with meta keys
$total = 0; if (false !== stripos($post['key'], '_KEVA_'))
foreach ((array) $client->kevaFilter($value['namespaceId']) as $post)
{ {
// Skip values with meta keys continue;
if (false !== stripos($post['key'], '_KEVA_'))
{
continue;
}
// Require valid kevachat meta
if ($this->_post($post))
{
$total++;
}
} }
// Add to room list // Require valid kevachat meta
$list[] = if ($this->_post($post))
[ {
'namespace' => $value['namespaceId'], $total++;
'total' => $total, }
'pinned' => in_array(
$value['namespaceId'],
(array) explode(
'|',
$this->getParameter('app.kevacoin.room.namespaces.pinned')
)
)
];
} }
// Sort by name // Add to room list
array_multisort( $list[] =
array_column( [
$list, 'namespace' => $value['namespaceId'],
'total' 'total' => $total,
), 'pinned' => in_array(
SORT_DESC, $value['namespaceId'],
$list (array) explode(
); '|',
$this->getParameter('app.kevacoin.room.namespaces.pinned')
// Cache rooms to memcached as kevaListNamespaces hides rooms with pending posts )
$memcached->set( )
$memory, ];
$list,
(int) $this->getParameter('app.memcached.timeout')
);
} }
// Sort by name
array_multisort(
array_column(
$list,
'total'
),
SORT_DESC,
$list
);
// RSS // RSS
if ('rss' === $request->get('feed')) if ('rss' === $request->get('feed'))
{ {