Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Improve av https://github.com/siyuan-note/siyuan/issues/14511

Danielfcd44f41daf7
diff --git a/kernel/av/filter.go b/kernel/av/filter.go
index 34fafbf8d1..207795059d 100644
--- a/kernel/av/filter.go
+++ b/kernel/av/filter.go
@@ -185,7 +185,7 @@ func (value *Value) Filter(filter *ViewFilter, attrView *AttributeView, rowID st
for _, blockID := range relVal.Relation.BlockIDs {
destVal := destAv.GetValue(key.Rollup.KeyID, blockID)
if nil == destVal {
- if destAv.ExistBlock(blockID) { // 数据库中存在行但是列值不存在是数据未初始化,这里补一个默认值
+ if destAv.ExistBlock(blockID) { // 数据库中存在项目但是字段值不存在是数据未初始化,这里补一个默认值
destVal = GetAttributeViewDefaultValue(ast.NewNodeID(), key.Rollup.KeyID, blockID, destKey.Type)
}
if nil == destVal {
diff --git a/kernel/av/value.go b/kernel/av/value.go
index 8e979d45e1..b74b15fbee 100644
--- a/kernel/av/value.go
+++ b/kernel/av/value.go
@@ -33,9 +33,9 @@ import (
type Value struct {
ID string `json:"id,omitempty"`
- KeyID string `json:"keyID,omitempty"`
- BlockID string `json:"blockID,omitempty"`
- Type KeyType `json:"type,omitempty"`
+ KeyID string `json:"keyID,omitempty"` // 字段 ID
+ BlockID string `json:"blockID,omitempty"` // 项目 ID
+ Type KeyType `json:"type,omitempty"` // 字段类型
IsDetached bool `json:"isDetached,omitempty"` // 是否为非绑定块,注意这个字段只能在主键(KeyTypeBlock)上使用,其他类型的值不要使用
CreatedAt int64 `json:"createdAt,omitempty"`
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index 0aa23683cc..d3c3570034 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -1384,7 +1384,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
for _, bID := range relVal.Relation.BlockIDs {
destVal := destAv.GetValue(kv.Key.Rollup.KeyID, bID)
if nil == destVal {
- if destAv.ExistBlock(bID) { // 数据库中存在行但是字段值不存在是数据未初始化,这里补一个默认值
+ if destAv.ExistBlock(bID) { // 数据库中存在项目但是字段值不存在是数据未初始化,这里补一个默认值
destVal = av.GetAttributeViewDefaultValue(ast.NewNodeID(), kv.Key.Rollup.KeyID, bID, destKey.Type)
}
if nil == destVal {
@@ -4135,18 +4135,13 @@ func BatchReplaceAttributeViewBlocks(avID string, isDetached bool, oldNew []map[
}
func (tx *Transaction) doUpdateAttrViewCell(operation *Operation) (ret *TxErr) {
- err := updateAttributeViewCell(operation, tx)
+ _, err := UpdateAttributeViewCell(tx, operation.AvID, operation.KeyID, operation.RowID, operation.Data)
if err != nil {
return &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}
}
return
}
-func updateAttributeViewCell(operation *Operation, tx *Transaction) (err error) {
- _, err = UpdateAttributeViewCell(tx, operation.AvID, operation.KeyID, operation.RowID, operation.Data)
- return
-}
-
func BatchUpdateAttributeViewCells(tx *Transaction, avID string, values []interface{}) (err error) {
attrView, err := av.ParseAttributeView(avID)
if err != nil {
@@ -4317,17 +4312,15 @@ func updateAttributeViewValue(tx *Transaction, attrView *av.AttributeView, keyID
if isUpdatingBlockKey {
if oldIsDetached {
- // 之前是游离行
+ // 之前是非绑定块
if !val.IsDetached { // 现在绑定了块
- // 将游离行绑定到新建的块上
bindBlockAv(tx, avID, val.Block.ID)
}
} else {
// 之前绑定了块
- if val.IsDetached { // 现在是游离行
- // 将绑定的块从属性视图中移除
+ if val.IsDetached { // 现在是非绑定块
unbindBlockAv(tx, avID, blockID)
} else {
// 现在也绑定了块
@@ -4343,6 +4336,7 @@ func updateAttributeViewValue(tx *Transaction, attrView *av.AttributeView, keyID
updateStaticText := true
_, blockText := getNodeAvBlockText(node)
if "" == content {
+ // 使用动态锚文本
val.Block.Content = util.UnescapeHTML(blockText)
} else {
if blockText == content {
diff --git a/kernel/sql/av.go b/kernel/sql/av.go
index 1082ccff58..209c0e8390 100644
--- a/kernel/sql/av.go
+++ b/kernel/sql/av.go
@@ -385,7 +385,7 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
}
if nil == destVal {
- if destAv.ExistBlock(blockID) { // 数据库中存在行但是列值不存在是数据未初始化,这里补一个默认值
+ if destAv.ExistBlock(blockID) { // 数据库中存在项目但是字段值不存在是数据未初始化,这里补一个默认值
destVal = av.GetAttributeViewDefaultValue(ast.NewNodeID(), rollupKey.Rollup.KeyID, blockID, destKey.Type)
}
if nil == destVal {