mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[Workspace Model] WIP use soft ids index for updating composite persistent ids
GitOrigin-RevId: f3d4e00378255c361c2905259a319d13788e45fd
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7d0f931566
commit
e74169b9a7
+12
@@ -136,6 +136,18 @@ internal class MutableStorageIndexes(
|
||||
persistentIdIndex.index(entityId)
|
||||
}
|
||||
|
||||
fun <T : WorkspaceEntity> simpleUpdateSoftReferences(copiedData: WorkspaceEntityData<T>) {
|
||||
val pid = copiedData.createPid()
|
||||
if (copiedData is SoftLinkable) {
|
||||
val beforeSoftLinks = HashSet(this.softLinks.getKeys(pid))
|
||||
val afterSoftLinks = copiedData.getLinks()
|
||||
if (beforeSoftLinks != afterSoftLinks) {
|
||||
beforeSoftLinks.forEach { this.softLinks.remove(it, pid) }
|
||||
afterSoftLinks.forEach { this.softLinks.put(it, pid) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
fun <T : WorkspaceEntity> updateSoftReferences(beforePersistentId: PersistentEntityId<*>?,
|
||||
copiedData: WorkspaceEntityData<T>,
|
||||
|
||||
+37
-6
@@ -121,15 +121,11 @@ internal class WorkspaceEntityStorageBuilderImpl(
|
||||
}
|
||||
|
||||
// Add an entry to changelog
|
||||
val pid = e.id
|
||||
val parents = this.refs.getParentRefsOfChild(pid)
|
||||
val children = this.refs.getChildrenRefsOfParentBy(pid)
|
||||
updateChangeLog { it.add(ChangeEntry.ReplaceEntity(copiedData, children, parents)) }
|
||||
addReplaceChange(copiedData)
|
||||
|
||||
val updatedEntity = copiedData.createEntity(this)
|
||||
|
||||
if (updatedEntity is WorkspaceEntityWithPersistentId) indexes.persistentIdIndex.index(pid, updatedEntity.persistentId())
|
||||
indexes.updateSoftReferences(beforePersistentId, copiedData, this)
|
||||
updatePersistentIdIndexes(updatedEntity, beforePersistentId, copiedData)
|
||||
|
||||
// Assert consistency
|
||||
this.assertConsistencyInStrictMode()
|
||||
@@ -137,6 +133,41 @@ internal class WorkspaceEntityStorageBuilderImpl(
|
||||
return updatedEntity
|
||||
}
|
||||
|
||||
private fun <T : WorkspaceEntity> updatePersistentIdIndexes(updatedEntity: WorkspaceEntity,
|
||||
beforePersistentId: PersistentEntityId<*>?,
|
||||
copiedData: WorkspaceEntityData<T>) {
|
||||
val pid = (updatedEntity as WorkspaceEntityBase).id
|
||||
if (updatedEntity is WorkspaceEntityWithPersistentId) {
|
||||
val newPersistentId = updatedEntity.persistentId()
|
||||
if (beforePersistentId != null && beforePersistentId != newPersistentId) {
|
||||
indexes.persistentIdIndex.index(pid, newPersistentId)
|
||||
updateComposedIds(beforePersistentId, newPersistentId)
|
||||
}
|
||||
}
|
||||
indexes.simpleUpdateSoftReferences(copiedData)
|
||||
}
|
||||
|
||||
private fun updateComposedIds(beforePersistentId: PersistentEntityId<*>, newPersistentId: PersistentEntityId<*> ) {
|
||||
val idsWithSoftRef = HashSet(indexes.softLinks.getValues(beforePersistentId))
|
||||
for (entityId in idsWithSoftRef) {
|
||||
val entity = this.entitiesByType.getEntityDataForModification(entityId)
|
||||
val editingBeforePersistentId = entity.persistentId(this)
|
||||
(entity as SoftLinkable).updateLink(beforePersistentId, newPersistentId, ArrayList())
|
||||
|
||||
// Add an entry to changelog
|
||||
addReplaceChange(entity)
|
||||
|
||||
updatePersistentIdIndexes(entity.createEntity(this), editingBeforePersistentId, entity)
|
||||
}
|
||||
}
|
||||
|
||||
private fun addReplaceChange(entity: WorkspaceEntityData<*>) {
|
||||
val pid = entity.createPid()
|
||||
val parents = this.refs.getParentRefsOfChild(pid)
|
||||
val children = this.refs.getChildrenRefsOfParentBy(pid)
|
||||
updateChangeLog { it.add(ChangeEntry.ReplaceEntity(entity, children, parents)) }
|
||||
}
|
||||
|
||||
override fun <T : WorkspaceEntity> changeSource(e: T, newSource: EntitySource): T {
|
||||
val copiedData = entitiesByType.getEntityDataForModification((e as WorkspaceEntityBase).id) as WorkspaceEntityData<T>
|
||||
copiedData.entitySource = newSource
|
||||
|
||||
Reference in New Issue
Block a user