mirror of
https://github.com/kevachat/webapp.git
synced 2025-02-04 10:54:51 +00:00
fix kevaNamespaceValue method, remove chache
This commit is contained in:
parent
ca91389ef0
commit
238c008738
@ -199,9 +199,6 @@ class AppExtension extends AbstractExtension
|
||||
return $texts[(($number % 100) > 4 && ($number % 100) < 20) ? 2 : $cases[min($number % 10, 5)]];
|
||||
}
|
||||
|
||||
// @TODO
|
||||
// this is fix of keva magic with Kevachat\Kevacoin\Client::kevaListNamespaces results (on pending transactions exist in the namespaces)
|
||||
// let's extract it from latest_KEVA_NS_ value and temporarily store results in memory cache
|
||||
public function kevaNamespaceValue(
|
||||
string $namespace
|
||||
): string
|
||||
@ -221,52 +218,13 @@ class AppExtension extends AbstractExtension
|
||||
$this->container->getParameter('app.kevacoin.password')
|
||||
);
|
||||
|
||||
// Connect memcached
|
||||
$memcached = new \Memcached();
|
||||
$memcached->addServer(
|
||||
$this->container->getParameter('app.memcached.host'),
|
||||
$this->container->getParameter('app.memcached.port')
|
||||
);
|
||||
|
||||
// Generate unique cache key
|
||||
$key = md5(
|
||||
sprintf(
|
||||
'%s.AppExtension::kevaNamespaceValue:%s',
|
||||
__DIR__,
|
||||
$namespace
|
||||
)
|
||||
);
|
||||
|
||||
// Return cached value if exists
|
||||
if ($value = $memcached->get($key))
|
||||
// Extract value from wallet
|
||||
if ($result = $client->kevaGet($namespace, '_KEVA_NS_'))
|
||||
{
|
||||
return $value;
|
||||
return (string) $result['value'];
|
||||
}
|
||||
|
||||
// Find related room names
|
||||
$_keva_ns = [];
|
||||
foreach ((array) $client->kevaFilter($namespace) as $data)
|
||||
{
|
||||
if ($data['key'] == '_KEVA_NS_')
|
||||
{
|
||||
$_keva_ns[$data['height']] = $data['value'];
|
||||
}
|
||||
}
|
||||
|
||||
// Get last by it block height
|
||||
if (!empty($_keva_ns))
|
||||
{
|
||||
$value = reset(
|
||||
$_keva_ns
|
||||
);
|
||||
|
||||
if ($memcached->set($key, $value, $this->container->getParameter('app.memcached.timeout')))
|
||||
{
|
||||
return (string) $value;
|
||||
}
|
||||
}
|
||||
|
||||
// Return original hash
|
||||
// Return original hash if no success
|
||||
return $namespace;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user