From 9c61d2a36f64447c5781e0597e58d56839949143 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 6 Apr 2024 10:50:25 +0800 Subject: [PATCH] :art: Improve doc dynamic loading https://github.com/siyuan-note/siyuan/issues/10851 --- kernel/conf/editor.go | 5 +++++ kernel/model/conf.go | 8 ++++---- kernel/model/file.go | 3 ++- kernel/treenode/node.go | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/kernel/conf/editor.go b/kernel/conf/editor.go index 2ea54e7d0..f7ec00378 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 a7a6fb1bc..d5b27a56f 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 90ce4656f..71def8279 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 d6b24408d..295fc3292 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 }