Browse Source

fix kevaNamespaceValue method, remove chache

main
ghost 12 months ago
parent
commit
238c008738
  1. 50
      src/Twig/AppExtension.php

50
src/Twig/AppExtension.php

@ -199,9 +199,6 @@ class AppExtension extends AbstractExtension @@ -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 @@ -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))
{
return $value;
}
// Find related room names
$_keva_ns = [];
foreach ((array) $client->kevaFilter($namespace) as $data)
// Extract value from wallet
if ($result = $client->kevaGet($namespace, '_KEVA_NS_'))
{
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 (string) $result['value'];
}
// Return original hash
// Return original hash if no success
return $namespace;
}
}
Loading…
Cancel
Save