Browse Source

memcache user list

main
ghost 9 months ago
parent
commit
d3d2a61056
  1. 76
      src/Controller/UserController.php

76
src/Controller/UserController.php

@ -50,6 +50,22 @@ class UserController extends AbstractController @@ -50,6 +50,22 @@ class UserController extends AbstractController
public function list(
?Request $request
): Response
{
// Connect memcached
$memcached = new \Memcached();
$memcached->addServer(
$this->getParameter('app.memcached.host'),
$this->getParameter('app.memcached.port')
);
$memory = md5(
sprintf(
'%s.UserController::list:list',
__DIR__,
),
);
if (!$list = $memcached->get($memory))
{
$list = [];
@ -81,19 +97,32 @@ class UserController extends AbstractController @@ -81,19 +97,32 @@ class UserController extends AbstractController
}
// Get room stats
$total = 0;
$rooms = [];
foreach ($this->_rooms($client) as $room => $name)
foreach ((array) $client->kevaListNamespaces() as $value)
{
if (empty($value['namespaceId']))
{
continue;
}
if (empty($value['displayName']))
{
continue;
}
if (str_starts_with($value['displayName'], '_'))
{
continue;
}
$posts = 0;
foreach ((array) $client->kevaFilter($room, sprintf('^[\d]+@%s$', $user['key'])) as $post)
foreach ((array) $client->kevaFilter($value['namespaceId'], sprintf('^[\d]+@%s$', $user['key'])) as $post)
{
$total++;
$posts++;
$rooms[$room] = $posts;
$rooms[$value['displayName']] = $posts;
}
}
@ -107,7 +136,6 @@ class UserController extends AbstractController @@ -107,7 +136,6 @@ class UserController extends AbstractController
'address' => $client->getAccountAddress(
$user['key']
),
'total' => $total,
'rooms' => $rooms,
];
}
@ -124,6 +152,13 @@ class UserController extends AbstractController @@ -124,6 +152,13 @@ class UserController extends AbstractController
$list
);
// Cache result
$memcached->set(
$memory,
$list
);
}
// RSS
if ('rss' === $request->get('feed'))
{
@ -882,35 +917,6 @@ class UserController extends AbstractController @@ -882,35 +917,6 @@ class UserController extends AbstractController
return null;
}
private function _rooms(
\Kevachat\Kevacoin\Client $client
): array
{
$rooms = [];
foreach ((array) $client->kevaListNamespaces() as $value)
{
if (empty($value['namespaceId']))
{
continue;
}
if (empty($value['displayName']))
{
continue;
}
if (str_starts_with($value['displayName'], '_'))
{
continue;
}
$rooms[$value['namespaceId']] = $value['displayName'];
}
return $rooms;
}
private function _hash(
\Kevachat\Kevacoin\Client $client,
string $namespace,

Loading…
Cancel
Save