From f9315288d0d7e79b02d17c6cee40db6985737a74 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Mon, 1 Aug 2016 20:48:55 +0200 Subject: [PATCH] found another bug that only happens in persistent databases (operationAdded changes an operation, so it needs to be retrieved again after calling it) --- src/Database.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Database.js b/src/Database.js index afad7c94..82ea4466 100644 --- a/src/Database.js +++ b/src/Database.js @@ -370,13 +370,12 @@ module.exports = function (Y /* :any */) { var opid = op.id var isGarbageCollected = yield* this.isGarbageCollected(opid) if (!isGarbageCollected) { + // TODO: reduce number of get / put calls for op .. yield* Y.Struct[op.struct].execute.call(this, op) yield* this.addOperation(op) yield* this.store.operationAdded(this, op) - if (!Y.utils.compareIds(opid, op.id)) { - // operationAdded changed op - op = yield* this.getOperation(opid) - } + // operationAdded can change op.. + op = yield* this.getOperation(opid) // if insertion, try to combine with left yield* this.tryCombineWithLeft(op) } @@ -440,6 +439,7 @@ module.exports = function (Y /* :any */) { // Delete if DS says this is actually deleted var len = op.content != null ? op.content.length : 1 var startId = op.id // You must not use op.id in the following loop, because op will change when deleted + // TODO: !! console.log('TODO: change this before commiting') for (let i = 0; i < len; i++) { var id = [startId[0], startId[1] + i] var opIsDeleted = yield* transaction.isDeleted(id)