From e08d621da7c91e65184c7af4fe9ef87198530d97 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 17 Feb 2023 10:44:44 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E7=BC=96=E8=BE=91=E5=99=A8=E4=B8=AD?= =?UTF-8?q?=E8=BE=93=E5=85=A5=20`#`=20=E5=90=8E=E6=A0=87=E7=AD=BE=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=8F=90=E7=A4=BA=E4=B8=8D=E5=85=A8=20Fix=20https://g?= =?UTF-8?q?ithub.com/siyuan-note/siyuan/issues/7391?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/graph.go | 2 +- kernel/model/tag.go | 6 +++--- kernel/sql/span.go | 20 +++++++++++++++++--- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/kernel/model/graph.go b/kernel/model/graph.go index 57894978d..7dde5f4a5 100644 --- a/kernel/model/graph.go +++ b/kernel/model/graph.go @@ -205,7 +205,7 @@ func BuildGraph(query string) (boxID string, nodes []*GraphNode, links []*GraphL } func linkTagBlocks(blocks *[]*Block, nodes *[]*GraphNode, links *[]*GraphLink, p string, style map[string]string) { - tagSpans := sql.QueryTagSpans(p, 1024) + tagSpans := sql.QueryTagSpans(p) if 1 > len(tagSpans) { return } diff --git a/kernel/model/tag.go b/kernel/model/tag.go index 6f2590b15..ddd06cf27 100644 --- a/kernel/model/tag.go +++ b/kernel/model/tag.go @@ -41,7 +41,7 @@ func RemoveTag(label string) (err error) { util.PushEndlessProgress(Conf.Language(116)) util.RandomSleep(1000, 2000) - tags := sql.QueryTagSpansByKeyword(label, 102400) + tags := sql.QueryTagSpansByLabel(label) treeBlocks := map[string][]string{} for _, tag := range tags { if blocks, ok := treeBlocks[tag.RootID]; !ok { @@ -126,7 +126,7 @@ func RenameTag(oldLabel, newLabel string) (err error) { util.PushEndlessProgress(Conf.Language(110)) util.RandomSleep(500, 1000) - tags := sql.QueryTagSpansByKeyword(oldLabel, 102400) + tags := sql.QueryTagSpansByLabel(oldLabel) treeBlocks := map[string][]string{} for _, tag := range tags { if blocks, ok := treeBlocks[tag.RootID]; !ok { @@ -310,7 +310,7 @@ func labelBlocksByKeyword(keyword string) (ret map[string]TagBlocks) { func labelTags() (ret map[string]Tags) { ret = map[string]Tags{} - tagSpans := sql.QueryTagSpans("", 10240) + tagSpans := sql.QueryTagSpans("") for _, tagSpan := range tagSpans { label := tagSpan.Content if _, ok := ret[label]; ok { diff --git a/kernel/sql/span.go b/kernel/sql/span.go index d445209d9..94e4623a4 100644 --- a/kernel/sql/span.go +++ b/kernel/sql/span.go @@ -80,8 +80,23 @@ func SelectSpansRawStmt(stmt string, limit int) (ret []*Span) { return } +func QueryTagSpansByLabel(label string) (ret []*Span) { + stmt := "SELECT * FROM spans WHERE type LIKE '%tag%' AND content LIKE '%" + label + "%' GROUP BY block_id" + rows, err := query(stmt) + if nil != err { + logging.LogErrorf("sql query failed: %s", err) + return + } + defer rows.Close() + for rows.Next() { + span := scanSpanRows(rows) + ret = append(ret, span) + } + return +} + func QueryTagSpansByKeyword(keyword string, limit int) (ret []*Span) { - stmt := "SELECT * FROM spans WHERE type LIKE '%tag%' AND content LIKE '%" + keyword + "%'" + stmt := "SELECT * FROM spans WHERE type LIKE '%tag%' AND content LIKE '%" + keyword + "%' GROUP BY markdown" stmt += " LIMIT " + strconv.Itoa(limit) rows, err := query(stmt) if nil != err { @@ -96,12 +111,11 @@ func QueryTagSpansByKeyword(keyword string, limit int) (ret []*Span) { return } -func QueryTagSpans(p string, limit int) (ret []*Span) { +func QueryTagSpans(p string) (ret []*Span) { stmt := "SELECT * FROM spans WHERE type LIKE '%tag%'" if "" != p { stmt += " AND path = '" + p + "'" } - stmt += " LIMIT " + strconv.Itoa(limit) rows, err := query(stmt) if nil != err { logging.LogErrorf("sql query failed: %s", err)