several bug fixes regarding "content is an array"

This commit is contained in:
Kevin Jahns 2016-04-07 15:54:47 +02:00
parent 5b21104da3
commit 08a79d0e7b
5 changed files with 59 additions and 31 deletions

View File

@ -4,7 +4,7 @@
module.exports = function (Y) { module.exports = function (Y) {
var globalRoom = { var globalRoom = {
users: {}, users: {},
buffers: {}, buffers: {}, // TODO: reimplement this idea. This does not cover all cases!! Here, you have a queue which is unrealistic (i.e. think about multiple incoming connections)
removeUser: function (user) { removeUser: function (user) {
for (var i in this.users) { for (var i in this.users) {
this.users[i].userLeft(user) this.users[i].userLeft(user)

View File

@ -146,9 +146,11 @@ module.exports = function (Y /* :any */) {
self.gc2 = [] self.gc2 = []
for (var i = 0; i < ungc.length; i++) { for (var i = 0; i < ungc.length; i++) {
var op = yield* this.getOperation(ungc[i]) var op = yield* this.getOperation(ungc[i])
if (op != null) {
delete op.gc delete op.gc
yield* this.setOperation(op) yield* this.setOperation(op)
} }
}
resolve() resolve()
}) })
}) })
@ -386,11 +388,11 @@ module.exports = function (Y /* :any */) {
let o = Y.utils.copyObject(op) let o = Y.utils.copyObject(op)
yield* t._changed(transaction, o) yield* t._changed(transaction, o)
} }
if (!op.deleted) {
// Delete if DS says this is actually deleted // Delete if DS says this is actually deleted
var len = op.content != null ? op.content.length : 1 var len = op.content != null ? op.content.length : 1
for (var i = 0; i < len; i++) { for (var i = 0; i < len; i++) {
var id = [op.id[0], op.id[1] + i] var id = [op.id[0], op.id[1] + i]
if (!op.deleted) {
var opIsDeleted = yield* transaction.isDeleted(id) var opIsDeleted = yield* transaction.isDeleted(id)
if (opIsDeleted) { if (opIsDeleted) {
var delop = { var delop = {

View File

@ -25,7 +25,7 @@ g.g = g
g.YConcurrency_TestingMode = true g.YConcurrency_TestingMode = true
jasmine.DEFAULT_TIMEOUT_INTERVAL = 2000 jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000
g.describeManyTimes = function describeManyTimes (times, name, f) { g.describeManyTimes = function describeManyTimes (times, name, f) {
for (var i = 0; i < times; i++) { for (var i = 0; i < times; i++) {
@ -200,7 +200,7 @@ g.compareAllUsers = async(function * compareAllUsers (users) {
for (var j in ds) { for (var j in ds) {
var d = ds[j] var d = ds[j]
for (var i = 0; i < d.len; i++) { for (var i = 0; i < d.len; i++) {
var o = yield* this.getOperation([d.id[0], d.id[1] + i]) var o = yield* this.getInsertion([d.id[0], d.id[1] + i])
// gc'd or deleted // gc'd or deleted
if (d.gc) { if (d.gc) {
expect(o).toBeFalsy() expect(o).toBeFalsy()

View File

@ -68,7 +68,7 @@ module.exports = function (Y/* :any */) {
if (op.hasOwnProperty('opContent')) { if (op.hasOwnProperty('opContent')) {
e.opContent = op.opContent e.opContent = op.opContent
} else { } else {
e.content = op.content e.content = op.content.slice()
} }
return e return e
@ -93,8 +93,11 @@ module.exports = function (Y/* :any */) {
return ids return ids
}, },
getDistanceToOrigin: function * (op) { getDistanceToOrigin: function * (op) {
if (op.left == null) {
return 0
} else {
var d = 0 var d = 0
var o = op var o = yield* this.getInsertion(op.left)
while (!Y.utils.matchesId(o, op.origin)) { while (!Y.utils.matchesId(o, op.origin)) {
d++ d++
if (o.left == null) { if (o.left == null) {
@ -104,6 +107,7 @@ module.exports = function (Y/* :any */) {
} }
} }
return d return d
}
}, },
/* /*
# $this has to find a unique position between origin and the next known character # $this has to find a unique position between origin and the next known character

View File

@ -160,12 +160,20 @@ module.exports = function (Y/* :any */) {
start.gc = true start.gc = true
start.deleted = true start.deleted = true
yield* this.setOperation(start) yield* this.setOperation(start)
yield* this.markDeleted(start.id, 1) var delLength = start.content != null ? start.content.length : 1
yield* this.markDeleted(start.id, delLength)
if (start.opContent != null) { if (start.opContent != null) {
yield* this.deleteOperation(start.opContent) yield* this.deleteOperation(start.opContent)
} }
if (this.store.y.connector.isSynced) { if (this.store.y.connector.isSynced) {
this.store.gc1.push(start.id) this.store.gc1.push(start.id)
for (var i = 0; i < delLength; i++) {
if (i === 0) {
this.store.gc1.push(start.id)
} else {
this.store.gc1.push([start.id[0], start.id[1] + i])
}
}
} }
} }
start = start.right start = start.right
@ -386,15 +394,22 @@ module.exports = function (Y/* :any */) {
*/ */
* garbageCollectAfterSync () { * garbageCollectAfterSync () {
yield* this.os.iterate(this, null, null, function * (op) { yield* this.os.iterate(this, null, null, function * (op) {
var opLength = op.content != null ? op.content.length : 1
if (op.gc) { if (op.gc) {
for (var i = 0; i < opLength; i++) {
if (i === 0) {
this.store.gc1.push(op.id) this.store.gc1.push(op.id)
} else {
this.store.gc1.push([op.id[0], op.id[1] + i])
}
}
} else { } else {
if (op.parent != null) { if (op.parent != null) {
var parentDeleted = yield* this.isDeleted(op.parent) var parentDeleted = yield* this.isDeleted(op.parent)
if (parentDeleted) { if (parentDeleted) {
op.gc = true op.gc = true
if (!op.deleted) { if (!op.deleted) {
yield* this.markDeleted(op.id, 1) yield* this.markDeleted(op.id, delLength)
op.deleted = true op.deleted = true
if (op.opContent != null) { if (op.opContent != null) {
yield* this.deleteOperation(op.opContent) yield* this.deleteOperation(op.opContent)
@ -412,7 +427,13 @@ module.exports = function (Y/* :any */) {
} }
} }
yield* this.setOperation(op) yield* this.setOperation(op)
for (var i = 0; i < opLength; i++) {
if (i === 0) {
this.store.gc1.push(op.id) this.store.gc1.push(op.id)
} else {
this.store.gc1.push([op.id[0], op.id[1] + i])
}
}
return return
} }
} }
@ -753,13 +774,17 @@ module.exports = function (Y/* :any */) {
} }
* getInsertion (id) { * getInsertion (id) {
var ins = yield* this.os.findWithUpperBound(id) var ins = yield* this.os.findWithUpperBound(id)
if (ins == null) {
return null
} else {
var len = ins.content != null ? ins.content.length : 1 // in case of opContent var len = ins.content != null ? ins.content.length : 1 // in case of opContent
if (ins != null && id[0] === ins.id[0] && id[1] < ins.id[1] + len) { if (id[0] === ins.id[0] && id[1] < ins.id[1] + len) {
return ins return ins
} else { } else {
return null return null
} }
} }
}
* getInsertionCleanStartEnd (id) { * getInsertionCleanStartEnd (id) {
yield* this.getInsertionCleanStart(id) yield* this.getInsertionCleanStart(id)
return yield* this.getInsertionCleanEnd(id) return yield* this.getInsertionCleanEnd(id)
@ -815,9 +840,6 @@ module.exports = function (Y/* :any */) {
} }
} }
* getOperation (id/* :any */)/* :Transaction<any> */ { * getOperation (id/* :any */)/* :Transaction<any> */ {
if (id.length > 2) {
id = [id[0], id[1]]
}
var o = yield* this.os.find(id) var o = yield* this.os.find(id)
if (id[0] !== '_' || o != null) { if (id[0] !== '_' || o != null) {
return o return o