mirror of
https://github.com/maximebf/php-debugbar.git
synced 2025-07-16 14:26:38 +02: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:
committed by
Barry vd. Heuvel
parent
9640a66b9c
commit
64251a3923
@ -34,7 +34,9 @@ class RedisStorage implements StorageInterface
|
|||||||
*/
|
*/
|
||||||
public function save($id, $data)
|
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)
|
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)
|
public function find(array $filters = array(), $max = 20, $offset = 0)
|
||||||
{
|
{
|
||||||
$results = array();
|
$results = array();
|
||||||
foreach ($this->redis->hgetall($this->hash) as $id => $data) {
|
$cursor = "0";
|
||||||
if ($data = unserialize($data)) {
|
do {
|
||||||
$meta = $data['__meta'];
|
list($cursor, $data) = $this->redis->hscan("$this->hash:meta", $cursor);
|
||||||
|
|
||||||
|
foreach ($data as $meta) {
|
||||||
|
if ($meta = unserialize($meta)) {
|
||||||
if ($this->filter($meta, $filters)) {
|
if ($this->filter($meta, $filters)) {
|
||||||
$results[] = $meta;
|
$results[] = $meta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} while($cursor);
|
||||||
|
|
||||||
usort($results, function ($a, $b) {
|
usort($results, function ($a, $b) {
|
||||||
return $a['utime'] < $b['utime'];
|
return $a['utime'] < $b['utime'];
|
||||||
|
Reference in New Issue
Block a user