From bdadaaf8def99c7169899bd104f9676fa88971c0 Mon Sep 17 00:00:00 2001 From: Sascha Lisson Date: Thu, 20 Feb 2025 10:47:25 +0100 Subject: [PATCH] fix(model-datastructure): deserialization failed after addNewChildren with empty list of children --- .../org/modelix/model/sync/bulk/AbstractModelSyncTest.kt | 2 -- .../org/modelix/model/operations/OTWriteTransaction.kt | 8 +++----- .../org/modelix/model/persistent/OperationSerializer.kt | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/bulk-model-sync-lib/src/commonTest/kotlin/org/modelix/model/sync/bulk/AbstractModelSyncTest.kt b/bulk-model-sync-lib/src/commonTest/kotlin/org/modelix/model/sync/bulk/AbstractModelSyncTest.kt index 1e37c4558e..bdd2302a2b 100644 --- a/bulk-model-sync-lib/src/commonTest/kotlin/org/modelix/model/sync/bulk/AbstractModelSyncTest.kt +++ b/bulk-model-sync-lib/src/commonTest/kotlin/org/modelix/model/sync/bulk/AbstractModelSyncTest.kt @@ -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 @@ -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, ) diff --git a/model-datastructure/src/commonMain/kotlin/org/modelix/model/operations/OTWriteTransaction.kt b/model-datastructure/src/commonMain/kotlin/org/modelix/model/operations/OTWriteTransaction.kt index bdad9d2f3a..7de6055293 100644 --- a/model-datastructure/src/commonMain/kotlin/org/modelix/model/operations/OTWriteTransaction.kt +++ b/model-datastructure/src/commonMain/kotlin/org/modelix/model/operations/OTWriteTransaction.kt @@ -69,11 +69,9 @@ class OTWriteTransaction( childIds: LongArray, concepts: Array, ) { - 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?) { diff --git a/model-datastructure/src/commonMain/kotlin/org/modelix/model/persistent/OperationSerializer.kt b/model-datastructure/src/commonMain/kotlin/org/modelix/model/persistent/OperationSerializer.kt index 243d075d52..dcc4e9b0fd 100644 --- a/model-datastructure/src/commonMain/kotlin/org/modelix/model/persistent/OperationSerializer.kt +++ b/model-datastructure/src/commonMain/kotlin/org/modelix/model/persistent/OperationSerializer.kt @@ -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) }