From 6bb89ed2e580bbc31b9350dd450c62bc154e8fe5 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Thu, 16 Nov 2023 20:34:50 +0800 Subject: [PATCH 1/2] :art: Repeated references to the same block within a block only count as one reference Fix https://github.com/siyuan-note/siyuan/issues/9670 --- kernel/model/index_fix.go | 4 ++-- kernel/sql/database.go | 23 +++++++++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/kernel/model/index_fix.go b/kernel/model/index_fix.go index 70b317225..ae8d4d330 100644 --- a/kernel/model/index_fix.go +++ b/kernel/model/index_fix.go @@ -73,8 +73,8 @@ func removeDuplicateDatabaseRefs() { refreshRefsByDefID(rootID) } - if 0 < len(duplicatedRootIDs) { - logging.LogWarnf("exist more than one ref duplicated [%d], reindex it", len(duplicatedRootIDs)) + for _, rootID := range duplicatedRootIDs { + logging.LogWarnf("exist more than one ref duplicated [%s], reindex it", rootID) } } diff --git a/kernel/sql/database.go b/kernel/sql/database.go index 86afea674..40c6cef2f 100644 --- a/kernel/sql/database.go +++ b/kernel/sql/database.go @@ -354,7 +354,9 @@ func refsFromTree(tree *parse.Tree) (refs []*Ref, fileAnnotationRefs []*FileAnno if treenode.IsBlockRef(n) { ref := buildRef(tree, n) - refs = append(refs, ref) + if !isRepeatedRef(refs, ref) { + refs = append(refs, ref) + } } else if treenode.IsFileAnnotationRef(n) { pathID := n.TextMarkFileAnnotationRefID idx := strings.LastIndex(pathID, "/") @@ -385,15 +387,32 @@ func refsFromTree(tree *parse.Tree) (refs []*Ref, fileAnnotationRefs []*FileAnno fileAnnotationRefs = append(fileAnnotationRefs, ref) } else if treenode.IsEmbedBlockRef(n) { ref := buildEmbedRef(tree, n) - refs = append(refs, ref) + if !isRepeatedRef(refs, ref) { + refs = append(refs, ref) + } } return ast.WalkContinue }) return } +func isRepeatedRef(refs []*Ref, ref *Ref) bool { + // Repeated references to the same block within a block only count as one reference https://github.com/siyuan-note/siyuan/issues/9670 + for _, r := range refs { + if r.DefBlockID == ref.DefBlockID && r.BlockID == ref.BlockID { + return true + } + } + return false +} + func buildRef(tree *parse.Tree, refNode *ast.Node) *Ref { + // 多个类型可能会导致渲染的 Markdown 不正确,所以这里只保留 block-ref 类型 + tmpTyp := refNode.TextMarkType + refNode.TextMarkType = "block-ref" markdown := treenode.ExportNodeStdMd(refNode, luteEngine) + refNode.TextMarkType = tmpTyp + defBlockID, text, _ := treenode.GetBlockRef(refNode) var defBlockParentID, defBlockRootID, defBlockPath string defBlock := treenode.GetBlockTree(defBlockID) From 5891ca5024e4f01c8ecf546a8580c085894a78be Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Thu, 16 Nov 2023 21:28:40 +0800 Subject: [PATCH 2/2] :arrow_up: Upgrade kernel deps --- kernel/go.mod | 6 +++--- kernel/go.sum | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/kernel/go.mod b/kernel/go.mod index c193f7bc6..162338b21 100644 --- a/kernel/go.mod +++ b/kernel/go.mod @@ -50,7 +50,7 @@ require ( github.com/rqlite/sql v0.0.0-20221103124402-8f9ff0ceb8f0 github.com/sashabaranov/go-openai v1.17.6 github.com/shirou/gopsutil/v3 v3.23.10 - github.com/siyuan-note/dejavu v0.0.0-20231114024923-42c60dc5343a + github.com/siyuan-note/dejavu v0.0.0-20231116132602-b8ba2e65471e github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 github.com/siyuan-note/eventbus v0.0.0-20230804030110-cf250f838c80 github.com/siyuan-note/filelock v0.0.0-20231107122348-6ed75b0b525a @@ -78,7 +78,7 @@ require ( github.com/andybalholm/brotli v1.0.6 // indirect github.com/andybalholm/cascadia v1.3.2 // indirect github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef // indirect - github.com/aws/aws-sdk-go v1.47.11 // indirect + github.com/aws/aws-sdk-go v1.47.12 // indirect github.com/bytedance/sonic v1.10.2 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect @@ -113,7 +113,7 @@ require ( github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/jolestar/go-commons-pool/v2 v2.1.2 // indirect github.com/juju/errors v1.0.0 // indirect - github.com/klauspost/compress v1.17.2 // indirect + github.com/klauspost/compress v1.17.3 // indirect github.com/klauspost/cpuid/v2 v2.2.6 // indirect github.com/leodido/go-urn v1.2.4 // indirect github.com/levigross/exp-html v0.0.0-20120902181939-8df60c69a8f5 // indirect diff --git a/kernel/go.sum b/kernel/go.sum index 55fe469e8..90061dde6 100644 --- a/kernel/go.sum +++ b/kernel/go.sum @@ -49,8 +49,8 @@ github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de h1:FxWPpzIjnTlhP github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoUhZrYW9p1lxo/cm8EmUOOzAPSEZNGF2DK1dJgw= github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef h1:2JGTg6JapxP9/R33ZaagQtAM4EkkSYnIAlOG5EI8gkM= github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef/go.mod h1:JS7hed4L1fj0hXcyEejnW57/7LCetXggd+vwrRnYeII= -github.com/aws/aws-sdk-go v1.47.11 h1:Dol+MA+hQblbnXUI3Vk9qvoekU6O1uDEuAItezjiWNQ= -github.com/aws/aws-sdk-go v1.47.11/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= +github.com/aws/aws-sdk-go v1.47.12 h1:1daICVijigVEXCzhg27A5d7hbkR4wODPGn9GHyBclKM= +github.com/aws/aws-sdk-go v1.47.12/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= github.com/bytedance/sonic v1.10.2 h1:GQebETVBxYB7JGWJtLBi07OVzWwt+8dWA00gEVW2ZFE= @@ -223,8 +223,8 @@ github.com/juju/errors v1.0.0/go.mod h1:B5x9thDqx0wIMH3+aLIMP9HjItInYWObRovoCFM5 github.com/juju/loggo v0.0.0-20190526231331-6e530bcce5d8/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U= github.com/juju/testing v0.0.0-20191001232224-ce9dec17d28b/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA= github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= -github.com/klauspost/compress v1.17.2 h1:RlWWUY/Dr4fL8qk9YG7DTZ7PDgME2V4csBXA8L/ixi4= -github.com/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/klauspost/compress v1.17.3 h1:qkRjuerhUU1EmXLYGkSH6EZL+vPSxIrYjLNAK4slzwA= +github.com/klauspost/compress v1.17.3/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.2.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc= @@ -356,8 +356,8 @@ github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFR github.com/shurcooL/gofontwoff v0.0.0-20181114050219-180f79e6909d h1:lvCTyBbr36+tqMccdGMwuEU+hjux/zL6xSmf5S9ITaA= github.com/shurcooL/gofontwoff v0.0.0-20181114050219-180f79e6909d/go.mod h1:05UtEgK5zq39gLST6uB0cf3NEHjETfB4Fgr3Gx5R9Vw= github.com/simplereach/timeutils v1.2.0/go.mod h1:VVbQDfN/FHRZa1LSqcwo4kNZ62OOyqLLGQKYB3pB0Q8= -github.com/siyuan-note/dejavu v0.0.0-20231114024923-42c60dc5343a h1:4VkGtdry3LDv6zyQSkTkp2BrYgyFt2lWIF7GROgYTFg= -github.com/siyuan-note/dejavu v0.0.0-20231114024923-42c60dc5343a/go.mod h1:g8x1cYUKzmvrjuV/EcTeb7EQmgWIYBZlRiDtM1TtNhI= +github.com/siyuan-note/dejavu v0.0.0-20231116132602-b8ba2e65471e h1:heA8v+BVj36pmq+5ROOfiwEimim9CZ8t6NT0QdAkQR0= +github.com/siyuan-note/dejavu v0.0.0-20231116132602-b8ba2e65471e/go.mod h1:g8x1cYUKzmvrjuV/EcTeb7EQmgWIYBZlRiDtM1TtNhI= github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 h1:Bi7/7f29LW+Fm0cHc0J1NO1cZqyJwljSWVmfOqVZgaE= github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw= github.com/siyuan-note/eventbus v0.0.0-20230804030110-cf250f838c80 h1:XghjHKJd+SiL0DkGYFVC+UGUDFtnR4v9gkAbPeh9Eq8=