🎨 API listDocsByPath
add an optional parameter maxListCount
Fix https://github.com/siyuan-note/siyuan/issues/7993
This commit is contained in:
parent
0b0712f741
commit
ee3138be64
4 changed files with 17 additions and 13 deletions
|
@ -95,7 +95,7 @@ func heading2Doc(c *gin.Context) {
|
|||
|
||||
name := path.Base(targetPath)
|
||||
box := model.Conf.Box(targetNotebook)
|
||||
files, _, _ := model.ListDocTree(targetNotebook, path.Dir(targetPath), model.Conf.FileTree.Sort, false)
|
||||
files, _, _ := model.ListDocTree(targetNotebook, path.Dir(targetPath), model.Conf.FileTree.Sort, false, model.Conf.FileTree.MaxListCount)
|
||||
evt := util.NewCmdResult("heading2doc", 0, util.PushModeBroadcast)
|
||||
evt.Data = map[string]interface{}{
|
||||
"box": box,
|
||||
|
@ -140,7 +140,7 @@ func li2Doc(c *gin.Context) {
|
|||
|
||||
name := path.Base(targetPath)
|
||||
box := model.Conf.Box(targetNotebook)
|
||||
files, _, _ := model.ListDocTree(targetNotebook, path.Dir(targetPath), model.Conf.FileTree.Sort, false)
|
||||
files, _, _ := model.ListDocTree(targetNotebook, path.Dir(targetPath), model.Conf.FileTree.Sort, false, model.Conf.FileTree.MaxListCount)
|
||||
evt := util.NewCmdResult("li2doc", 0, util.PushModeBroadcast)
|
||||
evt.Data = map[string]interface{}{
|
||||
"box": box,
|
||||
|
@ -448,7 +448,7 @@ func createDailyNote(c *gin.Context) {
|
|||
evt.AppId = app
|
||||
|
||||
name := path.Base(p)
|
||||
files, _, _ := model.ListDocTree(box.ID, path.Dir(p), model.Conf.FileTree.Sort, false)
|
||||
files, _, _ := model.ListDocTree(box.ID, path.Dir(p), model.Conf.FileTree.Sort, false, model.Conf.FileTree.MaxListCount)
|
||||
evt.Data = map[string]interface{}{
|
||||
"box": box,
|
||||
"path": p,
|
||||
|
@ -619,14 +619,18 @@ func listDocsByPath(c *gin.Context) {
|
|||
if arg["flashcard"] != nil {
|
||||
flashcard = arg["flashcard"].(bool)
|
||||
}
|
||||
maxListCount := model.Conf.FileTree.MaxListCount
|
||||
if arg["maxListCount"] != nil {
|
||||
maxListCount = int(arg["maxListCount"].(float64))
|
||||
}
|
||||
|
||||
files, totals, err := model.ListDocTree(notebook, p, sortMode, flashcard)
|
||||
files, totals, err := model.ListDocTree(notebook, p, sortMode, flashcard, maxListCount)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
if model.Conf.FileTree.MaxListCount < totals {
|
||||
if maxListCount < totals {
|
||||
util.PushMsg(fmt.Sprintf(model.Conf.Language(48), len(files)), 7000)
|
||||
}
|
||||
|
||||
|
@ -718,7 +722,7 @@ func getDoc(c *gin.Context) {
|
|||
func pushCreate(box *model.Box, p, treeID string, arg map[string]interface{}) {
|
||||
evt := util.NewCmdResult("create", 0, util.PushModeBroadcast)
|
||||
name := path.Base(p)
|
||||
files, _, _ := model.ListDocTree(box.ID, path.Dir(p), model.Conf.FileTree.Sort, false)
|
||||
files, _, _ := model.ListDocTree(box.ID, path.Dir(p), model.Conf.FileTree.Sort, false, model.Conf.FileTree.MaxListCount)
|
||||
evt.Data = map[string]interface{}{
|
||||
"box": box,
|
||||
"path": p,
|
||||
|
|
|
@ -110,7 +110,7 @@ func loadTreeNodes(box string, p string, level int) (ret []*ast.Node, err error)
|
|||
}
|
||||
|
||||
func buildBlockChildren(block *Block) (err error) {
|
||||
files, _, err := ListDocTree(block.Box, block.Path, Conf.FileTree.Sort, false)
|
||||
files, _, err := ListDocTree(block.Box, block.Path, Conf.FileTree.Sort, false, Conf.FileTree.MaxListCount)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -221,7 +221,7 @@ type FileInfo struct {
|
|||
isdir bool
|
||||
}
|
||||
|
||||
func ListDocTree(boxID, path string, sortMode int, flashcard bool) (ret []*File, totals int, err error) {
|
||||
func ListDocTree(boxID, path string, sortMode int, flashcard bool, maxListCount int) (ret []*File, totals int, err error) {
|
||||
//os.MkdirAll("pprof", 0755)
|
||||
//cpuProfile, _ := os.Create("pprof/cpu_profile_list_doc_tree")
|
||||
//pprof.StartCPUProfile(cpuProfile)
|
||||
|
@ -363,8 +363,8 @@ func ListDocTree(boxID, path string, sortMode int, flashcard bool) (ret []*File,
|
|||
return fileTreeFiles[i].Sort < fileTreeFiles[j].Sort
|
||||
})
|
||||
ret = append(ret, fileTreeFiles...)
|
||||
if Conf.FileTree.MaxListCount < len(ret) {
|
||||
ret = ret[:Conf.FileTree.MaxListCount]
|
||||
if maxListCount < len(ret) {
|
||||
ret = ret[:maxListCount]
|
||||
}
|
||||
ret = ret[:]
|
||||
return
|
||||
|
@ -390,8 +390,8 @@ func ListDocTree(boxID, path string, sortMode int, flashcard bool) (ret []*File,
|
|||
ret = append(ret, docs...)
|
||||
}
|
||||
|
||||
if Conf.FileTree.MaxListCount < len(ret) {
|
||||
ret = ret[:Conf.FileTree.MaxListCount]
|
||||
if maxListCount < len(ret) {
|
||||
ret = ret[:maxListCount]
|
||||
}
|
||||
ret = ret[:]
|
||||
|
||||
|
|
|
@ -194,7 +194,7 @@ func Mount(boxID string) (alreadyMount bool, err error) {
|
|||
|
||||
box.Index()
|
||||
// 缓存根一级的文档树展开
|
||||
ListDocTree(box.ID, "/", Conf.FileTree.Sort, false)
|
||||
ListDocTree(box.ID, "/", Conf.FileTree.Sort, false, Conf.FileTree.MaxListCount)
|
||||
treenode.SaveBlockTree(false)
|
||||
util.ClearPushProgress(100)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue