From 6b1cf18822f1f734df59687fd471990255d093b6 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Tue, 26 Jan 2016 11:29:58 +0100 Subject: [PATCH] Improvements on DS lookups --- gulpfile.helper.js | 4 ++-- src/Transaction.js | 24 +++++++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/gulpfile.helper.js b/gulpfile.helper.js index 58ae80f3..f57169d2 100644 --- a/gulpfile.helper.js +++ b/gulpfile.helper.js @@ -98,8 +98,8 @@ module.exports = function (gulp, helperOptions) { }).bundle() .pipe(source('specs.js')) .pipe(buffer()) - .pipe($.sourcemaps.init({loadMaps: true})) - .pipe($.sourcemaps.write('.')) + // .pipe($.sourcemaps.init({loadMaps: true})) + // .pipe($.sourcemaps.write('.')) .pipe(gulp.dest('./build/')) }) diff --git a/src/Transaction.js b/src/Transaction.js index c1e1db14..a4404f63 100644 --- a/src/Transaction.js +++ b/src/Transaction.js @@ -331,6 +331,7 @@ module.exports = function (Y/* :any */) { * garbageCollectOperation (id) { this.store.addToDebug('yield* this.garbageCollectOperation(', id, ')') // check to increase the state of the respective user + var o = null var state = yield* this.getState(id[0]) if (state.clock === id[1]) { state.clock++ @@ -338,11 +339,11 @@ module.exports = function (Y/* :any */) { yield* this.checkDeleteStoreForState(state) // then set the state yield* this.setState(state) - } - yield* this.markGarbageCollected(id) - + } else if (state.clock > id[1]) { + o = yield* this.getOperation(id) + } // else state.clock < id[1], don't clean up + yield* this.markGarbageCollected(id) // always mark gc'd // if op exists, then clean that mess up.. - var o = yield* this.getOperation(id) if (o != null) { /* if (!o.deleted) { @@ -363,7 +364,7 @@ module.exports = function (Y/* :any */) { var right = yield* this.getOperation(o.right) right.left = o.left - if (Y.utils.compareIds(right.origin, id)) { // rights origin is o + if (o.originOf != null && o.originOf.length > 0) { // find new origin of right ops // origin is the first left deleted operation var neworigin = o.left @@ -545,10 +546,15 @@ module.exports = function (Y/* :any */) { var del = deletions[i] var id = [del[0], del[1]] // always try to delete.. - var addOperation = yield* this.deleteOperation(id) - if (addOperation) { - // TODO:.. really .. here? You could prevent calling all these functions in operationAdded - yield* this.store.operationAdded(this, {struct: 'Delete', target: id}) + var state = yield* this.getState(id[0]) + if (id[1] < state.clock) { + var addOperation = yield* this.deleteOperation(id) + if (addOperation) { + // TODO:.. really .. here? You could prevent calling all these functions in operationAdded + yield* this.store.operationAdded(this, {struct: 'Delete', target: id}) + } + } else { + yield* this.markDeleted(id) } if (del[2]) { // gc