From c3d2a7b5423b39a6620249cec65060fec368007e Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sun, 7 Apr 2024 11:32:27 +0800 Subject: [PATCH 1/4] :art: Clean code --- kernel/treenode/tree.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/kernel/treenode/tree.go b/kernel/treenode/tree.go index 154a37f6f..c3e5a1dc0 100644 --- a/kernel/treenode/tree.go +++ b/kernel/treenode/tree.go @@ -33,17 +33,6 @@ import ( "github.com/siyuan-note/siyuan/kernel/util" ) -func StatTree(tree *parse.Tree) (ret *util.BlockStatResult) { - runeCnt, wordCnt, linkCnt, imgCnt, refCnt := tree.Root.Stat() - return &util.BlockStatResult{ - RuneCount: runeCnt, - WordCount: wordCnt, - LinkCount: linkCnt, - ImageCount: imgCnt, - RefCount: refCnt, - } -} - func NodeHash(node *ast.Node, tree *parse.Tree, luteEngine *lute.Lute) string { ialArray := node.KramdownIAL sort.Slice(ialArray, func(i, j int) bool { From 36bed84802d2fcb6709f5b29600fc4a030fd891f Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sun, 7 Apr 2024 11:32:42 +0800 Subject: [PATCH 2/4] :art: Database blocks are included in document word count https://github.com/siyuan-note/siyuan/issues/10918 --- kernel/model/file.go | 96 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/kernel/model/file.go b/kernel/model/file.go index 71def8279..6f2457da6 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -17,6 +17,7 @@ package model import ( + "bytes" "errors" "fmt" "os" @@ -448,6 +449,10 @@ func ListDocTree(boxID, listPath string, sortMode int, flashcard, showHidden boo func ContentStat(content string) (ret *util.BlockStatResult) { luteEngine := util.NewLute() + return contentStat(content, luteEngine) +} + +func contentStat(content string, luteEngine *lute.Lute) (ret *util.BlockStatResult) { tree := luteEngine.BlockDOM2Tree(content) runeCnt, wordCnt, linkCnt, imgCnt, refCnt := tree.Root.Stat() return &util.BlockStatResult{ @@ -479,6 +484,10 @@ func BlocksWordCount(ids []string) (ret *util.BlockStatResult) { } node := treenode.GetNodeInTree(tree, id) + if nil == node { + continue + } + runeCnt, wordCnt, linkCnt, imgCnt, refCnt := node.Stat() ret.RuneCount += runeCnt ret.WordCount += wordCnt @@ -497,7 +506,94 @@ func StatTree(id string) (ret *util.BlockStatResult) { return } + var databaseBlockNodes []*ast.Node + ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus { + if !entering || ast.NodeAttributeView != n.Type { + return ast.WalkContinue + } + + databaseBlockNodes = append(databaseBlockNodes, n) + return ast.WalkContinue + }) + + luteEngine := util.NewLute() + var dbRuneCnt, dbWordCnt, dbLinkCnt, dbImgCnt, dbRefCnt int + for _, n := range databaseBlockNodes { + if "" == n.AttributeViewID { + continue + } + + attrView, _ := av.ParseAttributeView(n.AttributeViewID) + if nil == attrView { + continue + } + + content := bytes.Buffer{} + for _, kValues := range attrView.KeyValues { + for _, v := range kValues.Values { + switch kValues.Key.Type { + case av.KeyTypeURL: + if v.IsEmpty() { + continue + } + + dbLinkCnt++ + content.WriteString(v.URL.Content) + case av.KeyTypeMAsset: + if v.IsEmpty() { + continue + } + + for _, asset := range v.MAsset { + if av.AssetTypeImage == asset.Type { + dbImgCnt++ + } + } + case av.KeyTypeBlock: + if v.IsEmpty() { + continue + } + + if !v.IsDetached { + dbRefCnt++ + } + content.WriteString(v.Block.Content) + case av.KeyTypeText: + if v.IsEmpty() { + continue + } + content.WriteString(v.Text.Content) + case av.KeyTypeNumber: + if v.IsEmpty() { + continue + } + v.Number.FormatNumber() + content.WriteString(v.Number.FormattedContent) + case av.KeyTypeEmail: + if v.IsEmpty() { + continue + } + content.WriteString(v.Email.Content) + case av.KeyTypePhone: + if v.IsEmpty() { + continue + } + content.WriteString(v.Phone.Content) + } + } + } + + dbStat := contentStat(content.String(), luteEngine) + dbRuneCnt += dbStat.RuneCount + dbWordCnt += dbStat.WordCount + } + runeCnt, wordCnt, linkCnt, imgCnt, refCnt := tree.Root.Stat() + runeCnt += dbRuneCnt + wordCnt += dbWordCnt + linkCnt += dbLinkCnt + imgCnt += dbImgCnt + refCnt += dbRefCnt return &util.BlockStatResult{ RuneCount: runeCnt, WordCount: wordCnt, From 65cdd1a3195d4c95ae96c70cb5bb00d04dc01f63 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sun, 7 Apr 2024 11:43:58 +0800 Subject: [PATCH 3/4] :art: Support floating window to open related database when filling in the database relation field https://github.com/siyuan-note/siyuan/issues/10915 --- kernel/model/attribute_view.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index c2789f539..791347376 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -64,6 +64,9 @@ func GetAttributeViewPrimaryKeyValues(avID, keyword string, page, pageSize int) return } attributeViewName = attrView.Name + if "" == attributeViewName { + attributeViewName = Conf.language(105) + } databaseBlockIDs = treenode.GetMirrorAttrViewBlockIDs(avID) From ca1be10f1783b0ff2e5f50506a581a1d52d16b90 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sun, 7 Apr 2024 11:59:27 +0800 Subject: [PATCH 4/4] :bug: Database rollup calculation range anomaly https://github.com/siyuan-note/siyuan/issues/10913 --- kernel/av/value.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/av/value.go b/kernel/av/value.go index 2a2793386..0a2728d5c 100644 --- a/kernel/av/value.go +++ b/kernel/av/value.go @@ -781,6 +781,10 @@ func (r *ValueRollup) RenderContents(calc *RollupCalc, destKey *Key) { r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewFormattedValueNumber(maxVal, destKey.NumberFormat)}} } case CalcOperatorRange: + if 2 > len(r.Contents) { + return + } + minVal := math.MaxFloat64 maxVal := -math.MaxFloat64 earliest := int64(0)