From 4b03360fb3fa652f5901eb56a8edb456018d4aae Mon Sep 17 00:00:00 2001 From: Alex Plate Date: Thu, 28 May 2020 16:37:09 +0300 Subject: [PATCH] [Workspace Model] Some fixes of addDiff GitOrigin-RevId: 8158422d727ed068d119b25ef87d07ce297b4288 --- .../workspaceModel-core/src/pstorage/PEntityStorage.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/platform/workspaceModel-core/src/pstorage/PEntityStorage.kt b/platform/workspaceModel-core/src/pstorage/PEntityStorage.kt index a7b5355b0d00..38901e4d68c7 100644 --- a/platform/workspaceModel-core/src/pstorage/PEntityStorage.kt +++ b/platform/workspaceModel-core/src/pstorage/PEntityStorage.kt @@ -456,7 +456,7 @@ internal class PEntityStorageBuilder( is ChangeEntry.RemoveEntity -> { val outdatedId = change.id val usedPid = replaceMap.getOrDefault(outdatedId, outdatedId) - indexes.removeFromIndices(outdatedId) + indexes.removeFromIndices(usedPid) if (this.entityDataById(usedPid) != null) { removeEntity(usedPid, replaceMap.inverse()) } @@ -473,9 +473,10 @@ internal class PEntityStorageBuilder( val newData = change.newData.clone() newData.id = usedPid.arrayId - indexes.updateIndices(outdatedId, newData.createPid(), builder) - updateChangeLog { it.add(ChangeEntry.ReplaceEntity(newData, updatedChildren, updatedParents)) } + // We don't modify entity that isn't exist in this version of storage if (this.entityDataById(usedPid) != null) { + indexes.updateIndices(outdatedId, newData.createPid(), builder) + updateChangeLog { it.add(ChangeEntry.ReplaceEntity(newData, updatedChildren, updatedParents)) } replaceEntityWithRefs(newData, outdatedId.clazz, updatedChildren, updatedParents) } }