Merge pull request #2003 from nextcloud/query-logger-limit

Cap the number of queries we save in the query logger
This commit is contained in:
Morris Jobke 2016-11-03 17:04:50 +01:00 committed by GitHub
commit 9e27e2f048
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();
}
}