]> source.dussan.org Git - nextcloud-server.git/commitdiff
Cap the number of queries we save in the query logger 2003/head
authorRobin Appelman <robin@icewind.nl>
Thu, 3 Nov 2016 13:35:44 +0000 (14:35 +0100)
committerRobin Appelman <robin@icewind.nl>
Thu, 3 Nov 2016 15:00:28 +0000 (16:00 +0100)
Signed-off-by: Robin Appelman <robin@icewind.nl>
lib/private/Cache/CappedMemoryCache.php
lib/private/Diagnostics/QueryLogger.php

index 29446c74bd9680b9caafd0186ed9aa2d7f03b65d..c6b45c49c1c10e699a300baf60b2eada6998b9ba 100644 (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) {
index a30f8c7b02a0be1055beb8d4bc36813498662a33..5f2a061a910c55aed2ee6c6ea130a7fb71064de3 100644 (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();
        }
 }