1
0
mirror of https://github.com/maximebf/php-debugbar.git synced 2025-01-16 21:08:34 +01:00

RedisStorage performance fix (#357)

Patch increases possible number of records stored and loaded from Redis DB by separating metadata and collector's data and storing them in different hashes.
This commit is contained in:
Dmytro Ilnicki 2017-09-13 15:19:36 +03:00 committed by Barry vd. Heuvel
parent 9640a66b9c
commit 64251a3923

View File

@ -34,7 +34,9 @@ class RedisStorage implements StorageInterface
*/
public function save($id, $data)
{
$this->redis->hset($this->hash, $id, serialize($data));
$this->redis->hset("$this->hash:meta", $id, serialize($data['__meta']));
unset($data['__meta']);
$this->redis->hset("$this->hash:data", $id, serialize($data));
}
/**
@ -42,7 +44,8 @@ class RedisStorage implements StorageInterface
*/
public function get($id)
{
return unserialize($this->redis->hget($this->hash, $id));
return array_merge(unserialize($this->redis->hget("$this->hash:data", $id)),
array('__meta' => unserialize($this->redis->hget("$this->hash:meta", $id))));
}
/**
@ -51,14 +54,18 @@ class RedisStorage implements StorageInterface
public function find(array $filters = array(), $max = 20, $offset = 0)
{
$results = array();
foreach ($this->redis->hgetall($this->hash) as $id => $data) {
if ($data = unserialize($data)) {
$meta = $data['__meta'];
if ($this->filter($meta, $filters)) {
$results[] = $meta;
$cursor = "0";
do {
list($cursor, $data) = $this->redis->hscan("$this->hash:meta", $cursor);
foreach ($data as $meta) {
if ($meta = unserialize($meta)) {
if ($this->filter($meta, $filters)) {
$results[] = $meta;
}
}
}
}
} while($cursor);
usort($results, function ($a, $b) {
return $a['utime'] < $b['utime'];