An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Skip ignored documents before changing their indexes https://github.com/siyuan-note/siyuan/issues/19462
Daniel65cf822b4332
diff --git a/kernel/sql/upsert.go b/kernel/sql/upsert.goindex e4578fee65..f631a41e4f 100644--- a/kernel/sql/upsert.go+++ b/kernel/sql/upsert.go@@ -443,6 +443,9 @@ func indexTree(tx *sql.Tx, tree *parse.Tree, context map[string]any) (err error)}func upsertTree(tx *sql.Tx, tree *parse.Tree, context map[string]any) (err error) {+ if isIndexIgnored(tree) {+ return+ }oldBlockHashes := queryBlockHashes(tx, tree.ID)blocks, spans, assets, attributes := fromTree(tree.Root, tree)newBlockHashes := map[string]string{}@@ -498,15 +501,19 @@ func upsertTree(tx *sql.Tx, tree *parse.Tree, context map[string]any) (err errorreturn err}+func isIndexIgnored(tree *parse.Tree) bool {+ if ignoreLines := getIndexIgnoreLines(); 0 < len(ignoreLines) {+ matcher := ignore.CompileIgnoreLines(ignoreLines...)+ return matcher.MatchesPath("/" + path.Join(tree.Box, tree.Path))+ }+ return false+}+func insertTree0(tx *sql.Tx, tree *parse.Tree, context map[string]any,blocks []*Block, spans []*Span, assets []*Asset, attributes []*Attribute,refs []*Ref, fileAnnotationRefs []*FileAnnotationRef) (err error) {- if ignoreLines := getIndexIgnoreLines(); 0 < len(ignoreLines) {- // Support ignore index https://github.com/siyuan-note/siyuan/issues/9198- matcher := ignore.CompileIgnoreLines(ignoreLines...)- if matcher.MatchesPath("/" + path.Join(tree.Box, tree.Path)) {- return- }+ if isIndexIgnored(tree) {+ return}if err = insertBlocks(tx, blocks, context); err != nil {diff --git a/kernel/sql/upsert_ignore_test.go b/kernel/sql/upsert_ignore_test.gonew file mode 100644index 0000000000..390047ac18--- /dev/null+++ b/kernel/sql/upsert_ignore_test.go@@ -0,0 +1,24 @@+package sql++import (+ "testing"++ "github.com/88250/lute/parse"+)++func TestUpsertIgnoredTreeDoesNotTouchDatabase(t *testing.T) {+ previousCached, previousLines := IndexIgnoreCached, indexIgnore+ IndexIgnoreCached, indexIgnore = true, []string{"/box/ignored.sy"}+ t.Cleanup(func() { IndexIgnoreCached, indexIgnore = previousCached, previousLines })+ tree := &parse.Tree{ID: "ignored", Box: "box", Path: "/ignored.sy"}+ // 忽略判断必须先于读取或删除索引,因此无需提供事务和文档内容。+ if err := upsertTree(nil, tree, nil); err != nil {+ t.Fatal(err)+ }+ if err := insertTree0(nil, tree, nil, nil, nil, nil, nil, nil, nil); err != nil {+ t.Fatal(err)+ }+ if isIndexIgnored(&parse.Tree{Box: "box", Path: "/included.sy"}) {+ t.Fatal("unmatched document was ignored")+ }+}