Cap the number of queries we save in the query logger

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2016-11-03 14:35:44 +01:00
parent 1c52d87821
commit 95ac9f60ce
No known key found for this signature in database
GPG Key ID: 425003AC385454C5
2 changed files with 15 additions and 2 deletions

View File

@ -77,6 +77,10 @@ class CappedMemoryCache implements ICache, \ArrayAccess {
$this->remove($offset);
}
public function getData() {
return $this->cache;
}
private function garbageCollect() {
while (count($this->cache) > $this->capacity) {

View File

@ -23,6 +23,7 @@
namespace OC\Diagnostics;
use OC\Cache\CappedMemoryCache;
use OCP\Diagnostics\IQueryLogger;
class QueryLogger implements IQueryLogger {
@ -34,7 +35,15 @@ class QueryLogger implements IQueryLogger {
/**
* @var \OC\Diagnostics\Query[]
*/
protected $queries = array();
protected $queries;
/**
* QueryLogger constructor.
*/
public function __construct() {
$this->queries = new CappedMemoryCache(1024);
}
/**
* @param string $sql
@ -65,6 +74,6 @@ class QueryLogger implements IQueryLogger {
* @return Query[]
*/
public function getQueries() {
return $this->queries;
return $this->queries->getData();
}
}