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: The word count of the selected block is inaccurate https://github.com/siyuan-note/siyuan/issues/12793
Daniel27618dd849c4
diff --git a/kernel/filesys/tree.go b/kernel/filesys/tree.goindex 654521b76c..3d7d9b63af 100644--- a/kernel/filesys/tree.go+++ b/kernel/filesys/tree.go@@ -43,19 +43,17 @@ func LoadTrees(ids []string) (ret map[string]*parse.Tree) {luteEngine := util.NewLute()var boxIDs []stringvar paths []string- blockIDs := map[string]string{}- seen := map[string]bool{}+ blockIDs := map[string][]string{}for _, bt := range bts {- key := bt.BoxID + bt.Path- if !seen[key] {- seen[key] = true- boxIDs = append(boxIDs, bt.BoxID)- paths = append(paths, bt.Path)- blockIDs[bt.RootID] = bt.ID+ boxIDs = append(boxIDs, bt.BoxID)+ paths = append(paths, bt.Path)+ if _, ok := blockIDs[bt.RootID]; !ok {+ blockIDs[bt.RootID] = []string{}}+ blockIDs[bt.RootID] = append(blockIDs[bt.RootID], bt.ID)}- trees, errs := batchLoadTrees(boxIDs, paths, luteEngine)+ trees, errs := BatchLoadTrees(boxIDs, paths, luteEngine)for i := range trees {tree := trees[i]err := errs[i]@@ -64,8 +62,10 @@ func LoadTrees(ids []string) (ret map[string]*parse.Tree) {continue}- id := blockIDs[tree.Root.ID]- ret[id] = tree+ bIDs := blockIDs[tree.Root.ID]+ for _, bID := range bIDs {+ ret[bID] = tree+ }}return}@@ -82,11 +82,18 @@ func LoadTree(boxID, p string, luteEngine *lute.Lute) (ret *parse.Tree, err erroreturn}-func batchLoadTrees(boxIDs, paths []string, luteEngine *lute.Lute) (ret []*parse.Tree, errs []error) {+func BatchLoadTrees(boxIDs, paths []string, luteEngine *lute.Lute) (ret []*parse.Tree, errs []error) {var wg sync.WaitGrouplock := sync.Mutex{}+ loaded := map[string]bool{}for i := range paths {+ if loaded[boxIDs[i]+paths[i]] {+ continue+ }++ loaded[boxIDs[i]+paths[i]] = truewg.Add(1)+go func(i int) {defer wg.Done()