From 95ac9f60ce4dda0302b108b9caf4e53f571db713 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 3 Nov 2016 14:35:44 +0100 Subject: [PATCH] Cap the number of queries we save in the query logger Signed-off-by: Robin Appelman --- lib/private/Cache/CappedMemoryCache.php | 4 ++++ lib/private/Diagnostics/QueryLogger.php | 13 +++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/private/Cache/CappedMemoryCache.php b/lib/private/Cache/CappedMemoryCache.php index 29446c74bd9..c6b45c49c1c 100644 --- a/lib/private/Cache/CappedMemoryCache.php +++ b/lib/private/Cache/CappedMemoryCache.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) { diff --git a/lib/private/Diagnostics/QueryLogger.php b/lib/private/Diagnostics/QueryLogger.php index a30f8c7b02a..5f2a061a910 100644 --- a/lib/private/Diagnostics/QueryLogger.php +++ b/lib/private/Diagnostics/QueryLogger.php @@ -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(); } } -- 2.39.5