Browse Source
Cap the number of queries we save in the query logger
Signed-off-by: Robin Appelman <robin@icewind.nl>
pull/2003/head
Robin Appelman
10 years ago
No known key found for this signature in database
GPG Key ID: 425003AC385454C5
2 changed files with
15 additions and
2 deletions
-
lib/private/Cache/CappedMemoryCache.php
-
lib/private/Diagnostics/QueryLogger.php
|
|
|
@ -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) { |
|
|
|
|
|
|
|
@ -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(); |
|
|
|
} |
|
|
|
} |