Explorar o código

Merge remote-tracking branch 'origin/dev' into dev

Vanessa hai 1 ano
pai
achega
0c4f54cf22

+ 13 - 0
kernel/api/av.go

@@ -26,6 +26,19 @@ import (
 	"github.com/siyuan-note/siyuan/kernel/util"
 )
 
+func getMirrorDatabaseBlocks(c *gin.Context) {
+	ret := gulu.Ret.NewResult()
+	defer c.JSON(http.StatusOK, ret)
+
+	arg, ok := util.JsonArg(c, ret)
+	if !ok {
+		return
+	}
+
+	avID := arg["avID"].(string)
+	ret.Data = av.GetMirrorBlockIDs(avID)
+}
+
 func searchTableView(c *gin.Context) {
 	ret := gulu.Ret.NewResult()
 	defer c.JSON(http.StatusOK, ret)

+ 1 - 0
kernel/api/router.go

@@ -414,6 +414,7 @@ func ServeAPI(ginServer *gin.Engine) {
 	ginServer.Handle("POST", "/api/av/getAttributeViewPrimaryKeyValues", model.CheckAuth, model.CheckReadonly, getAttributeViewPrimaryKeyValues)
 	ginServer.Handle("POST", "/api/av/setDatabaseBlockView", model.CheckAuth, model.CheckReadonly, setDatabaseBlockView)
 	ginServer.Handle("POST", "/api/av/searchTableView", model.CheckAuth, model.CheckReadonly, searchTableView)
+	ginServer.Handle("POST", "/api/av/getMirrorDatabaseBlocks", model.CheckAuth, model.CheckReadonly, getMirrorDatabaseBlocks)
 
 	ginServer.Handle("POST", "/api/ai/chatGPT", model.CheckAuth, chatGPT)
 	ginServer.Handle("POST", "/api/ai/chatGPTWithAction", model.CheckAuth, chatGPTWithAction)

+ 2 - 6
kernel/av/filter.go

@@ -77,12 +77,8 @@ const (
 
 func (filter *ViewFilter) GetAffectValue(key *Key, defaultVal *Value) (ret *Value) {
 	if nil != filter.Value {
-		if filter.Value.IsGenerated() {
-			// 自动生成类型的过滤条件不设置默认值
-			return nil
-		}
-		if KeyTypeRelation == filter.Value.Type {
-			// 关联类型的过滤条件不设置默认值 https://ld246.com/article/1709608533749
+		if KeyTypeRelation == filter.Value.Type || KeyTypeTemplate == filter.Value.Type || KeyTypeRollup == filter.Value.Type || KeyTypeUpdated == filter.Value.Type || KeyTypeCreated == filter.Value.Type {
+			// 所有生成的数据都不设置默认值
 			return nil
 		}
 	}

+ 58 - 20
kernel/av/table.go

@@ -86,11 +86,19 @@ func (value *Value) Compare(other *Value) int {
 	switch value.Type {
 	case KeyTypeBlock:
 		if nil != value.Block && nil != other.Block {
-			return strings.Compare(value.Block.Content, other.Block.Content)
+			ret := strings.Compare(value.Block.Content, other.Block.Content)
+			if 0 == ret {
+				ret = int(value.CreatedAt - other.CreatedAt)
+			}
+			return ret
 		}
 	case KeyTypeText:
 		if nil != value.Text && nil != other.Text {
-			return strings.Compare(value.Text.Content, other.Text.Content)
+			ret := strings.Compare(value.Text.Content, other.Text.Content)
+			if 0 == ret {
+				ret = int(value.CreatedAt - other.CreatedAt)
+			}
+			return ret
 		}
 	case KeyTypeNumber:
 		if nil != value.Number && nil != other.Number {
@@ -104,7 +112,7 @@ func (value *Value) Compare(other *Value) int {
 				} else if value.Number.Content < other.Number.Content {
 					return -1
 				} else {
-					return 0
+					return int(value.CreatedAt - other.CreatedAt)
 				}
 			} else {
 				if other.Number.IsNotEmpty {
@@ -124,7 +132,7 @@ func (value *Value) Compare(other *Value) int {
 				} else if value.Date.Content < other.Date.Content {
 					return -1
 				} else {
-					return 0
+					return int(value.CreatedAt - other.CreatedAt)
 				}
 			} else {
 				if other.Date.IsNotEmpty {
@@ -140,7 +148,7 @@ func (value *Value) Compare(other *Value) int {
 			} else if value.Created.Content < other.Created.Content {
 				return -1
 			} else {
-				return 0
+				return int(value.CreatedAt - other.CreatedAt)
 			}
 		}
 	case KeyTypeUpdated:
@@ -150,7 +158,7 @@ func (value *Value) Compare(other *Value) int {
 			} else if value.Updated.Content < other.Updated.Content {
 				return -1
 			} else {
-				return 0
+				return int(value.CreatedAt - other.CreatedAt)
 			}
 		}
 	case KeyTypeSelect, KeyTypeMSelect:
@@ -163,19 +171,35 @@ func (value *Value) Compare(other *Value) int {
 			for _, v := range other.MSelect {
 				v2 += v.Content
 			}
-			return strings.Compare(v1, v2)
+			ret := strings.Compare(v1, v2)
+			if 0 == ret {
+				ret = int(value.CreatedAt - other.CreatedAt)
+			}
+			return ret
 		}
 	case KeyTypeURL:
 		if nil != value.URL && nil != other.URL {
-			return strings.Compare(value.URL.Content, other.URL.Content)
+			ret := strings.Compare(value.URL.Content, other.URL.Content)
+			if 0 == ret {
+				ret = int(value.CreatedAt - other.CreatedAt)
+			}
+			return ret
 		}
 	case KeyTypeEmail:
 		if nil != value.Email && nil != other.Email {
-			return strings.Compare(value.Email.Content, other.Email.Content)
+			ret := strings.Compare(value.Email.Content, other.Email.Content)
+			if 0 == ret {
+				ret = int(value.CreatedAt - other.CreatedAt)
+			}
+			return ret
 		}
 	case KeyTypePhone:
 		if nil != value.Phone && nil != other.Phone {
-			return strings.Compare(value.Phone.Content, other.Phone.Content)
+			ret := strings.Compare(value.Phone.Content, other.Phone.Content)
+			if 0 == ret {
+				ret = int(value.CreatedAt - other.CreatedAt)
+			}
+			return ret
 		}
 	case KeyTypeMAsset:
 		if nil != value.MAsset && nil != other.MAsset {
@@ -187,7 +211,11 @@ func (value *Value) Compare(other *Value) int {
 			for _, v := range other.MAsset {
 				v2 += v.Content
 			}
-			return strings.Compare(v1, v2)
+			ret := strings.Compare(v1, v2)
+			if 0 == ret {
+				ret = int(value.CreatedAt - other.CreatedAt)
+			}
+			return ret
 		}
 	case KeyTypeTemplate:
 		if nil != value.Template && nil != other.Template {
@@ -199,13 +227,16 @@ func (value *Value) Compare(other *Value) int {
 				if v1 > v2 {
 					return 1
 				}
-
 				if v1 < v2 {
 					return -1
 				}
-				return 0
+				return int(value.CreatedAt - other.CreatedAt)
 			}
-			return strings.Compare(value.Template.Content, other.Template.Content)
+			ret := strings.Compare(value.Template.Content, other.Template.Content)
+			if 0 == ret {
+				ret = int(value.CreatedAt - other.CreatedAt)
+			}
+			return ret
 		}
 	case KeyTypeCheckbox:
 		if nil != value.Checkbox && nil != other.Checkbox {
@@ -215,7 +246,7 @@ func (value *Value) Compare(other *Value) int {
 			if !value.Checkbox.Checked && other.Checkbox.Checked {
 				return -1
 			}
-			return 0
+			return int(value.CreatedAt - other.CreatedAt)
 		}
 	case KeyTypeRelation:
 		if nil != value.Relation && nil != other.Relation {
@@ -242,9 +273,13 @@ func (value *Value) Compare(other *Value) int {
 				if v1 < v2 {
 					return -1
 				}
-				return 0
+				return int(value.CreatedAt - other.CreatedAt)
 			}
-			return strings.Compare(vContent, oContent)
+			ret := strings.Compare(vContent, oContent)
+			if 0 == ret {
+				ret = int(value.CreatedAt - other.CreatedAt)
+			}
+			return ret
 		}
 	case KeyTypeRollup:
 		if nil != value.Rollup && nil != other.Rollup {
@@ -267,13 +302,16 @@ func (value *Value) Compare(other *Value) int {
 				if v1 > v2 {
 					return 1
 				}
-
 				if v1 < v2 {
 					return -1
 				}
-				return 0
+				return int(value.CreatedAt - other.CreatedAt)
+			}
+			ret := strings.Compare(vContent, oContent)
+			if 0 == ret {
+				ret = int(value.CreatedAt - other.CreatedAt)
 			}
-			return strings.Compare(vContent, oContent)
+			return ret
 		}
 	}
 	return int(value.CreatedAt - other.CreatedAt)

+ 2 - 3
kernel/av/value.go

@@ -193,8 +193,7 @@ func (value *Value) IsEdited() bool {
 		return true
 	}
 
-	if value.IsGenerated() {
-		// 所有生成的数据都认为是编辑过的
+	if KeyTypeUpdated == value.Type || KeyTypeCreated == value.Type {
 		return true
 	}
 
@@ -206,7 +205,7 @@ func (value *Value) IsEdited() bool {
 }
 
 func (value *Value) IsGenerated() bool {
-	return KeyTypeTemplate == value.Type || KeyTypeRollup == value.Type || KeyTypeUpdated == value.Type || KeyTypeCreated == value.Type
+	return KeyTypeUpdated == value.Type || KeyTypeCreated == value.Type
 }
 
 func (value *Value) IsEmpty() bool {

+ 4 - 2
kernel/model/attribute_view.go

@@ -1007,7 +1007,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
 				for _, blockID := range relVal.Relation.BlockIDs {
 					destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID)
 					if nil == destVal {
-						destVal = treenode.GetAttributeViewDefaultValue(ast.NewNodeID(), rollupKey.Rollup.KeyID, blockID, destKey.Type)
+						continue
 					}
 					if av.KeyTypeNumber == destKey.Type {
 						destVal.Number.Format = destKey.NumberFormat
@@ -1034,7 +1034,9 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
 							blocks[blockValue.BlockID] = blockValue
 						}
 						for _, blockID := range cell.Value.Relation.BlockIDs {
-							cell.Value.Relation.Contents = append(cell.Value.Relation.Contents, blocks[blockID])
+							if val := blocks[blockID]; nil != val {
+								cell.Value.Relation.Contents = append(cell.Value.Relation.Contents, val)
+							}
 						}
 					}
 				}

+ 1 - 1
kernel/treenode/node.go

@@ -805,7 +805,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
 				for _, blockID := range relVal.Relation.BlockIDs {
 					destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID)
 					if nil == destVal {
-						destVal = GetAttributeViewDefaultValue(ast.NewNodeID(), rollupKey.Rollup.KeyID, blockID, destKey.Type)
+						continue
 					}
 					if av.KeyTypeNumber == destKey.Type {
 						destVal.Number.Format = destKey.NumberFormat