Skip to content

Commit

Permalink
fix(model-datastructure): deserialization failed after addNewChildren…
Browse files Browse the repository at this point in the history
… with empty list of children
  • Loading branch information
slisson committed Feb 28, 2025
1 parent 5143b51 commit bdadaaf
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.modelix.model.data.ModelData
import org.modelix.model.lazy.CLTree
import org.modelix.model.lazy.ObjectStoreCache
import org.modelix.model.operations.AddNewChildOp
import org.modelix.model.operations.AddNewChildrenOp
import org.modelix.model.operations.DeleteNodeOp
import org.modelix.model.operations.IOperation
import org.modelix.model.operations.MoveNodeOp
Expand Down Expand Up @@ -581,7 +580,6 @@ abstract class AbstractModelSyncTest {
SetReferenceOp::class to 3,
MoveNodeOp::class to 6, // could be done in 5, but finding that optimization makes the sync algorithm slower
AddNewChildOp::class to 1,
AddNewChildrenOp::class to 1,
DeleteNodeOp::class to 1,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ class OTWriteTransaction(
childIds: LongArray,
concepts: Array<IConceptReference?>,
) {
var index_ = index
if (index_ == -1) {
index_ = getChildren(parentId, role).count()
}
apply(AddNewChildrenOp(PositionInRole(parentId, role, index_), childIds, concepts))
if (childIds.isEmpty()) return
val index = if (index != -1) index else getChildren(parentId, role).count()
apply(AddNewChildrenOp(PositionInRole(parentId, role, index), childIds, concepts))
}

override fun addNewChild(parentId: Long, role: String?, index: Int, childId: Long, concept: IConcept?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class OperationSerializer private constructor() {

override fun deserialize(serialized: String): AddNewChildrenOp {
val parts = serialized.split(SEPARATOR).toTypedArray()
val ids = parts[3].split(Separators.LEVEL4).map { longFromHex(it) }.toLongArray()
val ids = parts[3].split(Separators.LEVEL4).filter { it.isNotEmpty() }.map { longFromHex(it) }.toLongArray()
val concepts = parts[4].split(Separators.LEVEL4).map { deserializeConcept(it) }.toTypedArray()
return AddNewChildrenOp(PositionInRole(longFromHex(parts[0]), unescape(parts[1]), parts[2].toInt()), ids, concepts)
}
Expand Down

0 comments on commit bdadaaf

Please sign in to comment.