diff --git a/src/Connector.js b/src/Connector.js index a93d115e..582ee11b 100644 --- a/src/Connector.js +++ b/src/Connector.js @@ -144,11 +144,6 @@ module.exports = function (Y/* :any */) { this.whenSyncedListeners.push(f) } } - /* - - returns false, if there is no sync target - true otherwise - */ findNextSyncTarget () { if (this.y == null) { debugger @@ -179,16 +174,20 @@ module.exports = function (Y/* :any */) { }) }) } else { - this.y.db.requestTransaction(function *() { - // it is crucial that isSynced is set at the time garbageCollectAfterSync is called - conn.isSynced = true - yield* this.garbageCollectAfterSync() - // call whensynced listeners - for (var f of conn.whenSyncedListeners) { - f() - } - conn.whenSyncedListeners = [] - }) + if (!conn.isSynced) { + this.y.db.requestTransaction(function *() { + if (!conn.isSynced) { + // it is crucial that isSynced is set at the time garbageCollectAfterSync is called + conn.isSynced = true + yield* this.garbageCollectAfterSync() + // call whensynced listeners + for (var f of conn.whenSyncedListeners) { + f() + } + conn.whenSyncedListeners = [] + } + }) + } } } send (uid, message) { diff --git a/src/Database.js b/src/Database.js index bbce6ae5..7bfe6cfa 100644 --- a/src/Database.js +++ b/src/Database.js @@ -85,7 +85,7 @@ module.exports = function (Y /* :any */) { function garbageCollect () { return os.whenTransactionsFinished().then(function () { if (os.gc1.length > 0 || os.gc2.length > 0) { - if (!os.y.isSynced) { + if (!os.y.connector.isSynced) { console.warn('gc should be empty when not synced!') } return new Promise((resolve) => { @@ -155,7 +155,7 @@ module.exports = function (Y /* :any */) { clearInterval(this.repairCheckIntervalHandler) } queueGarbageCollector (id) { - if (this.y.isSynced && this.gc) { + if (this.y.connector.isSynced && this.gc) { this.gc1.push(id) } } @@ -221,7 +221,7 @@ module.exports = function (Y /* :any */) { op.gc == null && op.deleted === true && this.store.gc && - this.store.y.isSynced + this.store.y.connector.isSynced ) { var gc = false if (left != null && left.deleted === true) { diff --git a/src/Transaction.js b/src/Transaction.js index b6d91828..2ddddc61 100644 --- a/src/Transaction.js +++ b/src/Transaction.js @@ -96,7 +96,7 @@ module.exports = function (Y/* :any */) { send.push(Y.Struct[op.struct].encode(op)) } } - if (!this.store.y.connector.isDisconnected() && send.length > 0) { // TODO: && !this.store.forwardAppliedOperations (but then i don't send delete ops) + if (this.store.y.connector.isSynced && send.length > 0) { // TODO: && !this.store.forwardAppliedOperations (but then i don't send delete ops) // is connected, and this is not going to be send in addOperation this.store.y.connector.broadcastOps(send) } @@ -714,7 +714,7 @@ module.exports = function (Y/* :any */) { } * addOperation (op) { yield* this.os.put(op) - if (!this.store.y.connector.isDisconnected() && this.store.forwardAppliedOperations && typeof op.id[1] !== 'string') { + if (this.store.y.connector.isSynced && this.store.forwardAppliedOperations && typeof op.id[1] !== 'string') { // is connected, and this is not going to be send in addOperation this.store.y.connector.broadcastOps([op]) }