An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Fix missing database tab in block attribute panel after binding (blockIALCache key mismatch) #18200
Daniel0006996208a6
diff --git a/kernel/cache/ial.go b/kernel/cache/ial.goindex 2ebf56ed7b..1ed7e4af14 100644--- a/kernel/cache/ial.go+++ b/kernel/cache/ial.go@@ -143,6 +143,20 @@ func GetBlockIALInBox(id, boxID string) (ret map[string]string) {return ial.(map[string]string)}+// GetBlockIALWithBoxFallback 先查 box-aware key,未命中再回退到 bare key。+//+// 写入端存在两套键命名空间:部分路径写 box-aware key(PutBlockIALInBox,用于加密笔记本隔离),+// 部分历史路径仍写 bare key(PutBlockIAL)。读取端若只查其一会漏掉另一侧的更新,因此这里按+// box-aware 优先、bare key 回退的顺序查询,与 treenode.GetDynamicRefText 的回退策略保持一致。+func GetBlockIALWithBoxFallback(id, boxID string) (ret map[string]string) {+ if "" != boxID {+ if ret = GetBlockIALInBox(id, boxID); nil != ret {+ return+ }+ }+ return GetBlockIAL(id)+}+func RemoveBlockIAL(id string) {blockIALCacheKeysMu.Lock()keys := blockIALCacheKeys[id]diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.goindex 13d6e5ea6b..067aac6b5c 100644--- a/kernel/model/attribute_view.go+++ b/kernel/model/attribute_view.go@@ -6117,11 +6117,11 @@ func updateBoundBlockAvsAttribute(avIDs []string) {attrs[av.NodeAttrViewNames] = avNames}- oldAttrs, setErr := setNodeAttrs0(node, attrs, "")+ oldAttrs, setErr := setNodeAttrs0(node, attrs, bt.BoxID)if nil != setErr {continue}- cache.PutBlockIAL(node.ID, parse.IAL2Map(node.KramdownIAL))+ cache.PutBlockIALInBox(node.ID, bt.BoxID, parse.IAL2Map(node.KramdownIAL))pushBlockAttrs(oldAttrs, node)if "" != avNames {node.RemoveIALAttr(av.NodeAttrViewNames)diff --git a/kernel/model/bookmark.go b/kernel/model/bookmark.goindex 73dd21a042..04987b5f4e 100644--- a/kernel/model/bookmark.go+++ b/kernel/model/bookmark.go@@ -68,7 +68,7 @@ func RemoveBookmark(bookmark string) (err error) {if bookmarkAttrVal := node.IALAttr("bookmark"); bookmarkAttrVal == bookmark {node.RemoveIALAttr("bookmark")- cache.PutBlockIAL(node.ID, parse.IAL2Map(node.KramdownIAL))+ cache.PutBlockIALInBox(node.ID, tree.Box, parse.IAL2Map(node.KramdownIAL))changed = true}}@@ -140,7 +140,7 @@ func RenameBookmark(oldBookmark, newBookmark string) (err error) {if bookmarkAttrVal := node.IALAttr("bookmark"); bookmarkAttrVal == oldBookmark {node.SetIALAttr("bookmark", newBookmark)- cache.PutBlockIAL(node.ID, parse.IAL2Map(node.KramdownIAL))+ cache.PutBlockIALInBox(node.ID, tree.Box, parse.IAL2Map(node.KramdownIAL))changed = true}}diff --git a/kernel/model/flashcard.go b/kernel/model/flashcard.goindex 6cb6f70288..09dc8a5fa1 100644--- a/kernel/model/flashcard.go+++ b/kernel/model/flashcard.go@@ -835,7 +835,7 @@ func (tx *Transaction) removeBlocksDeckAttr(blockIDs []string, deckID string) (etx.writeTree(tree)- cache.PutBlockIAL(blockID, parse.IAL2Map(node.KramdownIAL))+ cache.PutBlockIALInBox(blockID, tree.Box, parse.IAL2Map(node.KramdownIAL))pushBlockAttrs(oldAttrs, node)}@@ -933,7 +933,7 @@ func (tx *Transaction) doAddFlashcards(operation *Operation) (ret *TxErr) {tx.writeTree(tree)- cache.PutBlockIAL(blockID, parse.IAL2Map(node.KramdownIAL))+ cache.PutBlockIALInBox(blockID, tree.Box, parse.IAL2Map(node.KramdownIAL))pushBlockAttrs(oldAttrs, node)}diff --git a/kernel/sql/block.go b/kernel/sql/block.goindex cf2e786afa..fcd0c2d177 100644--- a/kernel/sql/block.go+++ b/kernel/sql/block.go@@ -362,7 +362,11 @@ func BatchGetBlockAttrsWitTrees(ids []string, trees map[string]*parse.Tree) (rethitCache := truefor _, id := range ids {- ial := cache.GetBlockIAL(id)+ boxID := ""+ if tree := trees[id]; nil != tree {+ boxID = tree.Box+ }+ ial := cache.GetBlockIALWithBoxFallback(id, boxID)if nil != ial {ret[id] = ialcontinue@@ -390,7 +394,11 @@ func BatchGetBlockAttrs(ids []string) (ret map[string]map[string]string) {hitCache := truefor _, id := range ids {- ial := cache.GetBlockIAL(id)+ boxID := ""+ if bt := treenode.GetBlockTree(id); nil != bt {+ boxID = bt.BoxID+ }+ ial := cache.GetBlockIALWithBoxFallback(id, boxID)if nil != ial {ret[id] = ialcontinue@@ -416,12 +424,24 @@ func BatchGetBlockAttrs(ids []string) (ret map[string]map[string]string) {func GetBlockAttrs(id string) (ret map[string]string) {ret = map[string]string{}- if cached := cache.GetBlockIAL(id); nil != cached {+ // 写入端部分路径用 box-aware key、部分用 bare key,这里按 box-aware 优先、bare key 回退查询,+ // 避免漏掉任一命名空间的更新(如块绑定数据库后写 box-aware key,但旧 bare key 仍是绑定前旧值)。+ bt := treenode.GetBlockTree(id)+ boxID := ""+ if nil != bt {+ boxID = bt.BoxID+ }+ if cached := cache.GetBlockIALWithBoxFallback(id, boxID); nil != cached {ret = cachedreturn}- tree := loadTreeByBlockID(id)+ var tree *parse.Tree+ if nil != bt {+ tree, _ = filesys.LoadTree(bt.BoxID, bt.Path, luteEngine)+ } else {+ tree = loadTreeByBlockID(id)+ }if nil == tree {return}@@ -433,7 +453,7 @@ func GetBlockAttrs(id string) (ret map[string]string) {func getBlockAttrsFromTree(id string, tree *parse.Tree) (ret map[string]string) {ret = map[string]string{}- ial := cache.GetBlockIAL(id)+ ial := cache.GetBlockIALWithBoxFallback(id, tree.Box)if nil != ial {for k, v := range ial {ret[k] = v@@ -450,7 +470,7 @@ func getBlockAttrsFromTree(id string, tree *parse.Tree) (ret map[string]string)for _, kv := range node.KramdownIAL {ret[kv[0]] = html.UnescapeAttrVal(kv[1])}- cache.PutBlockIAL(id, ret)+ cache.PutBlockIALInBox(id, tree.Box, ret)return}