Browse Source

add room list memcache

main
ghost 9 months ago
parent
commit
3c4e74724c
  1. 117
      src/Controller/RoomController.php

117
src/Controller/RoomController.php

@ -49,6 +49,13 @@ class RoomController extends AbstractController
?Request $request ?Request $request
): Response ): Response
{ {
// Connect memcached
$memcached = new \Memcached();
$memcached->addServer(
$this->getParameter('app.memcached.host'),
$this->getParameter('app.memcached.port')
);
// Connect kevacoin // Connect kevacoin
$client = new \Kevachat\Kevacoin\Client( $client = new \Kevachat\Kevacoin\Client(
$this->getParameter('app.kevacoin.protocol'), $this->getParameter('app.kevacoin.protocol'),
@ -59,62 +66,78 @@ class RoomController extends AbstractController
); );
// Get room list // Get room list
$list = []; $memory = md5(
sprintf(
'%s.RoomController::list:list',
__DIR__,
),
);
foreach ((array) $client->kevaListNamespaces() as $value) if (!$list = $memcached->get($memory))
{ {
// Skip system namespaces $list = [];
if (str_starts_with($value['displayName'], '_'))
foreach ((array) $client->kevaListNamespaces() as $value)
{ {
continue; // Skip system namespaces
if (str_starts_with($value['displayName'], '_'))
{
continue;
}
// Add to room list
$list[$value['namespaceId']] = // keep unique
[
'namespace' => $value['namespaceId'],
'total' => $this->_total(
$value['namespaceId']
),
'pinned' => in_array(
$value['namespaceId'],
(array) explode(
'|',
$this->getParameter('app.kevacoin.room.namespaces.pinned')
)
)
];
} }
// Add to room list // Get rooms contain pending data
$list[$value['namespaceId']] = // keep unique foreach ((array) $client->kevaPending() as $value)
[ {
'namespace' => $value['namespaceId'], // Add to room list
'total' => $this->_total( $list[$value['namespace']] = // keep unique
$value['namespaceId'] [
), 'namespace' => $value['namespace'],
'pinned' => in_array( 'total' => $this->_total(
$value['namespaceId'], $value['namespace']
(array) explode( ),
'|', 'pinned' => in_array(
$this->getParameter('app.kevacoin.room.namespaces.pinned') $value['namespaceId'],
(array) explode(
'|',
$this->getParameter('app.kevacoin.room.namespaces.pinned')
)
) )
) ];
]; }
}
// Get rooms contain pending data // Sort by name
foreach ((array) $client->kevaPending() as $value) array_multisort(
{ array_column(
// Add to room list $list,
$list[$value['namespace']] = // keep unique 'total'
[
'namespace' => $value['namespace'],
'total' => $this->_total(
$value['namespace']
), ),
'pinned' => in_array( SORT_DESC,
$value['namespaceId'], $list
(array) explode( );
'|',
$this->getParameter('app.kevacoin.room.namespaces.pinned')
)
)
];
}
// Sort by name // Cache result
array_multisort( $memcached->set(
array_column( $memory,
$list, $list
'total' );
), }
SORT_DESC,
$list
);
// RSS // RSS
if ('rss' === $request->get('feed')) if ('rss' === $request->get('feed'))

Loading…
Cancel
Save