Browse Source

memcache user list

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

176
src/Controller/UserController.php

@ -51,78 +51,113 @@ class UserController extends AbstractController
?Request $request ?Request $request
): Response ): Response
{ {
$list = []; // Connect memcached
$memcached = new \Memcached();
$memcached->addServer(
$this->getParameter('app.memcached.host'),
$this->getParameter('app.memcached.port')
);
// Check client connection $memory = md5(
if ($client = $this->_client()) sprintf(
'%s.UserController::list:list',
__DIR__,
),
);
if (!$list = $memcached->get($memory))
{ {
// Check users database accessible $list = [];
if ($namespace = $this->_namespace($client))
// Check client connection
if ($client = $this->_client())
{ {
// Collect usernames // Check users database accessible
foreach ((array) $client->kevaFilter($namespace) as $user) if ($namespace = $this->_namespace($client))
{ {
// Check record valid // Collect usernames
if (empty($user['key']) || empty($user['height'])) foreach ((array) $client->kevaFilter($namespace) as $user)
{
continue;
}
// Skip values with meta keys
if (str_starts_with($user['key'], '_'))
{ {
continue; // Check record valid
} if (empty($user['key']) || empty($user['height']))
{
continue;
}
// Validate username regex // Skip values with meta keys
if (!preg_match($this->getParameter('app.add.user.name.regex'), $user['key'])) if (str_starts_with($user['key'], '_'))
{ {
continue; continue;
} }
// Get room stats // Validate username regex
$total = 0; if (!preg_match($this->getParameter('app.add.user.name.regex'), $user['key']))
$rooms = []; {
continue;
}
foreach ($this->_rooms($client) as $room => $name) // Get room stats
{ $rooms = [];
$posts = 0;
foreach ((array) $client->kevaFilter($room, sprintf('^[\d]+@%s$', $user['key'])) as $post) foreach ((array) $client->kevaListNamespaces() as $value)
{ {
$total++; if (empty($value['namespaceId']))
$posts++; {
continue;
}
if (empty($value['displayName']))
{
continue;
}
if (str_starts_with($value['displayName'], '_'))
{
continue;
}
$posts = 0;
$rooms[$room] = $posts; foreach ((array) $client->kevaFilter($value['namespaceId'], sprintf('^[\d]+@%s$', $user['key'])) as $post)
{
$posts++;
$rooms[$value['displayName']] = $posts;
}
} }
}
$list[] = $list[] =
[ [
'name' => $user['key'], 'name' => $user['key'],
'balance' => $client->getBalance( 'balance' => $client->getBalance(
$user['key'], $user['key'],
$this->getParameter('app.pool.confirmations') $this->getParameter('app.pool.confirmations')
), ),
'address' => $client->getAccountAddress( 'address' => $client->getAccountAddress(
$user['key'] $user['key']
), ),
'total' => $total, 'rooms' => $rooms,
'rooms' => $rooms, ];
]; }
} }
} }
}
// Sort by height // Sort by height
array_multisort( array_multisort(
array_column( array_column(
$list, $list,
'total' 'total'
), ),
SORT_DESC, SORT_DESC,
$list $list
); );
// Cache result
$memcached->set(
$memory,
$list
);
}
// RSS // RSS
if ('rss' === $request->get('feed')) if ('rss' === $request->get('feed'))
@ -882,35 +917,6 @@ class UserController extends AbstractController
return null; 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( private function _hash(
\Kevachat\Kevacoin\Client $client, \Kevachat\Kevacoin\Client $client,
string $namespace, string $namespace,

Loading…
Cancel
Save