Skip to content

Commit

Permalink
🎨 Remove rows in database bound to child blocks when deleting parent …
Browse files Browse the repository at this point in the history
…block #10923
  • Loading branch information
88250 committed Apr 7, 2024
1 parent c148659 commit 20ecabc
Showing 1 changed file with 36 additions and 23 deletions.
59 changes: 36 additions & 23 deletions kernel/model/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,35 +811,48 @@ func removeAvBlockRel(node *ast.Node) {
}

func syncDelete2AttributeView(node *ast.Node) {
avs := node.IALAttr(av.NodeAttrNameAvs)
if "" == avs {
return
}

avIDs := strings.Split(avs, ",")
for _, avID := range avIDs {
attrView, parseErr := av.ParseAttributeView(avID)
if nil != parseErr {
continue
changedAvIDs := hashset.New()
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering || !n.IsBlock() {
return ast.WalkContinue
}

changedAv := false
blockValues := attrView.GetBlockKeyValues()
if nil == blockValues {
continue
avs := n.IALAttr(av.NodeAttrNameAvs)
if "" == avs {
return ast.WalkContinue
}

for i, blockValue := range blockValues.Values {
if blockValue.Block.ID == node.ID {
blockValues.Values = append(blockValues.Values[:i], blockValues.Values[i+1:]...)
changedAv = true
break
avIDs := strings.Split(avs, ",")
for _, avID := range avIDs {
attrView, parseErr := av.ParseAttributeView(avID)
if nil != parseErr {
continue
}

changedAv := false
blockValues := attrView.GetBlockKeyValues()
if nil == blockValues {
continue
}

for i, blockValue := range blockValues.Values {
if blockValue.Block.ID == n.ID {
blockValues.Values = append(blockValues.Values[:i], blockValues.Values[i+1:]...)
changedAv = true
break
}
}

if changedAv {
av.SaveAttributeView(attrView)
changedAvIDs.Add(avID)
}
}
if changedAv {
av.SaveAttributeView(attrView)
util.BroadcastByType("protyle", "refreshAttributeView", 0, "", map[string]interface{}{"id": avID})
}
return ast.WalkContinue
})

for _, avID := range changedAvIDs.Values() {
util.BroadcastByType("protyle", "refreshAttributeView", 0, "", map[string]interface{}{"id": avID})
}
}

Expand Down

0 comments on commit 20ecabc

Please sign in to comment.