mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-19 16:10:12 +01:00
🎨 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)
|
name := path.Base(targetPath)
|
||||||
box := model.Conf.Box(targetNotebook)
|
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 := util.NewCmdResult("heading2doc", 0, util.PushModeBroadcast)
|
||||||
evt.Data = map[string]interface{}{
|
evt.Data = map[string]interface{}{
|
||||||
"box": box,
|
"box": box,
|
||||||
|
|
@ -140,7 +140,7 @@ func li2Doc(c *gin.Context) {
|
||||||
|
|
||||||
name := path.Base(targetPath)
|
name := path.Base(targetPath)
|
||||||
box := model.Conf.Box(targetNotebook)
|
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 := util.NewCmdResult("li2doc", 0, util.PushModeBroadcast)
|
||||||
evt.Data = map[string]interface{}{
|
evt.Data = map[string]interface{}{
|
||||||
"box": box,
|
"box": box,
|
||||||
|
|
@ -448,7 +448,7 @@ func createDailyNote(c *gin.Context) {
|
||||||
evt.AppId = app
|
evt.AppId = app
|
||||||
|
|
||||||
name := path.Base(p)
|
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{}{
|
evt.Data = map[string]interface{}{
|
||||||
"box": box,
|
"box": box,
|
||||||
"path": p,
|
"path": p,
|
||||||
|
|
@ -619,14 +619,18 @@ func listDocsByPath(c *gin.Context) {
|
||||||
if arg["flashcard"] != nil {
|
if arg["flashcard"] != nil {
|
||||||
flashcard = arg["flashcard"].(bool)
|
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 {
|
if nil != err {
|
||||||
ret.Code = -1
|
ret.Code = -1
|
||||||
ret.Msg = err.Error()
|
ret.Msg = err.Error()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if model.Conf.FileTree.MaxListCount < totals {
|
if maxListCount < totals {
|
||||||
util.PushMsg(fmt.Sprintf(model.Conf.Language(48), len(files)), 7000)
|
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{}) {
|
func pushCreate(box *model.Box, p, treeID string, arg map[string]interface{}) {
|
||||||
evt := util.NewCmdResult("create", 0, util.PushModeBroadcast)
|
evt := util.NewCmdResult("create", 0, util.PushModeBroadcast)
|
||||||
name := path.Base(p)
|
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{}{
|
evt.Data = map[string]interface{}{
|
||||||
"box": box,
|
"box": box,
|
||||||
"path": p,
|
"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) {
|
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 {
|
if nil != err {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -221,7 +221,7 @@ type FileInfo struct {
|
||||||
isdir bool
|
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)
|
//os.MkdirAll("pprof", 0755)
|
||||||
//cpuProfile, _ := os.Create("pprof/cpu_profile_list_doc_tree")
|
//cpuProfile, _ := os.Create("pprof/cpu_profile_list_doc_tree")
|
||||||
//pprof.StartCPUProfile(cpuProfile)
|
//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
|
return fileTreeFiles[i].Sort < fileTreeFiles[j].Sort
|
||||||
})
|
})
|
||||||
ret = append(ret, fileTreeFiles...)
|
ret = append(ret, fileTreeFiles...)
|
||||||
if Conf.FileTree.MaxListCount < len(ret) {
|
if maxListCount < len(ret) {
|
||||||
ret = ret[:Conf.FileTree.MaxListCount]
|
ret = ret[:maxListCount]
|
||||||
}
|
}
|
||||||
ret = ret[:]
|
ret = ret[:]
|
||||||
return
|
return
|
||||||
|
|
@ -390,8 +390,8 @@ func ListDocTree(boxID, path string, sortMode int, flashcard bool) (ret []*File,
|
||||||
ret = append(ret, docs...)
|
ret = append(ret, docs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if Conf.FileTree.MaxListCount < len(ret) {
|
if maxListCount < len(ret) {
|
||||||
ret = ret[:Conf.FileTree.MaxListCount]
|
ret = ret[:maxListCount]
|
||||||
}
|
}
|
||||||
ret = ret[:]
|
ret = ret[:]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -194,7 +194,7 @@ func Mount(boxID string) (alreadyMount bool, err error) {
|
||||||
|
|
||||||
box.Index()
|
box.Index()
|
||||||
// 缓存根一级的文档树展开
|
// 缓存根一级的文档树展开
|
||||||
ListDocTree(box.ID, "/", Conf.FileTree.Sort, false)
|
ListDocTree(box.ID, "/", Conf.FileTree.Sort, false, Conf.FileTree.MaxListCount)
|
||||||
treenode.SaveBlockTree(false)
|
treenode.SaveBlockTree(false)
|
||||||
util.ClearPushProgress(100)
|
util.ClearPushProgress(100)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue