From 480dfdfb77a29dfed1ac14a5fcea48efcbcbb0fb Mon Sep 17 00:00:00 2001
From: Kevin Jahns <kevin.jahns@rwth-aachen.de>
Date: Wed, 2 Nov 2016 20:55:24 +0100
Subject: [PATCH] dont modify gc buffer if gcTimeout > 0 or disconnected

---
 src/Database.js | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/Database.js b/src/Database.js
index 2b5e5ca4..faa27c5f 100644
--- a/src/Database.js
+++ b/src/Database.js
@@ -149,7 +149,7 @@ module.exports = function (Y /* :any */) {
       clearInterval(this.repairCheckIntervalHandler)
     }
     queueGarbageCollector (id) {
-      if (this.y.isConnected()) {
+      if (this.y.isConnected() && this.gcTimeout > 0) {
         this.gc1.push(id)
       }
     }
@@ -204,7 +204,7 @@ module.exports = function (Y /* :any */) {
       TODO: rename this function
 
       Rulez:
-      * Only gc if this user is online
+      * Only gc if this user is online & gcTimeout > 0
       * The most left element in a list must not be gc'd.
         => There is at least one element in the list
 
@@ -213,7 +213,9 @@ module.exports = function (Y /* :any */) {
     * addToGarbageCollector (op, left) {
       if (
         op.gc == null &&
-        op.deleted === true
+        op.deleted === true &&
+        this.store.gcTimeout > 0 &&
+        this.y.isConnected()
       ) {
         var gc = false
         if (left != null && left.deleted === true) {