Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Improve doc dynamic loading https://github.com/siyuan-note/siyuan/issues/10851

Daniel9c61d2a36f64
diff --git a/kernel/conf/editor.go b/kernel/conf/editor.go
index 2ea54e7d0e..f7ec003785 100644
--- a/kernel/conf/editor.go
+++ b/kernel/conf/editor.go
@@ -50,6 +50,11 @@ type Editor struct {
BackmentionExpandCount int `json:"backmentionExpandCount"` // 反链提及默认展开数量
}
+const (
+ MinDynamicLoadBlocks = 48
+ MaxDynamicLoadBlocks = 1024
+)
+
func NewEditor() *Editor {
return &Editor{
FontSize: 16,
diff --git a/kernel/model/conf.go b/kernel/model/conf.go
index a7a6fb1bc5..d5b27a56f1 100644
--- a/kernel/model/conf.go
+++ b/kernel/model/conf.go
@@ -242,11 +242,11 @@ func InitConf() {
if 1 > Conf.Editor.HistoryRetentionDays {
Conf.Editor.HistoryRetentionDays = 30
}
- if 48 > Conf.Editor.DynamicLoadBlocks {
- Conf.Editor.DynamicLoadBlocks = 48
+ if conf.MinDynamicLoadBlocks > Conf.Editor.DynamicLoadBlocks {
+ Conf.Editor.DynamicLoadBlocks = conf.MinDynamicLoadBlocks
}
- if 1024 < Conf.Editor.DynamicLoadBlocks {
- Conf.Editor.DynamicLoadBlocks = 1024
+ if conf.MaxDynamicLoadBlocks < Conf.Editor.DynamicLoadBlocks {
+ Conf.Editor.DynamicLoadBlocks = conf.MaxDynamicLoadBlocks
}
if 0 > Conf.Editor.BacklinkExpandCount {
Conf.Editor.BacklinkExpandCount = 0
diff --git a/kernel/model/file.go b/kernel/model/file.go
index 90ce4656fb..71def82790 100644
--- a/kernel/model/file.go
+++ b/kernel/model/file.go
@@ -42,6 +42,7 @@ import (
"github.com/siyuan-note/riff"
"github.com/siyuan-note/siyuan/kernel/av"
"github.com/siyuan-note/siyuan/kernel/cache"
+ "github.com/siyuan-note/siyuan/kernel/conf"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/search"
"github.com/siyuan-note/siyuan/kernel/sql"
@@ -665,7 +666,7 @@ func GetDoc(startID, endID, id string, index int, query string, queryTypes map[s
childCount += treenode.CountBlockNodes(n)
}
- if childCount > Conf.Editor.DynamicLoadBlocks {
+ if childCount > Conf.Editor.DynamicLoadBlocks && blockCount > conf.MinDynamicLoadBlocks {
scroll = true
return ast.WalkStop
}
diff --git a/kernel/treenode/node.go b/kernel/treenode/node.go
index d6b24408d5..295fc32927 100644
--- a/kernel/treenode/node.go
+++ b/kernel/treenode/node.go
@@ -342,7 +342,7 @@ func FirstLeafBlock(node *ast.Node) (ret *ast.Node) {
func CountBlockNodes(node *ast.Node) (ret int) {
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
- if !entering || !n.IsBlock() || ast.NodeList == n.Type || ast.NodeBlockquote == n.Type || ast.NodeSuperBlock == n.Type {
+ if !entering || !n.IsBlock() || ast.NodeList == n.Type || ast.NodeListItem == n.Type || ast.NodeBlockquote == n.Type || ast.NodeSuperBlock == n.Type {
return ast.WalkContinue
}