Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel
2026-04-19 16:20:07 +08:00
parent 2d052a9400
commit 77d30f5fa7
2 changed files with 44 additions and 16 deletions

View File

@@ -19,8 +19,10 @@ package model
import (
"errors"
"fmt"
"path/filepath"
"sort"
"strings"
"time"
"github.com/88250/gulu"
"github.com/88250/lute/parse"
@@ -37,14 +39,16 @@ func RemoveBookmark(bookmark string) (err error) {
bookmarks := sql.QueryBookmarkBlocks()
treeBlocks := map[string][]string{}
for _, tag := range bookmarks {
if blocks, ok := treeBlocks[tag.RootID]; !ok {
treeBlocks[tag.RootID] = []string{tag.ID}
for _, bm := range bookmarks {
if blocks, ok := treeBlocks[bm.RootID]; !ok {
treeBlocks[bm.RootID] = []string{bm.ID}
} else {
treeBlocks[tag.RootID] = append(blocks, tag.ID)
treeBlocks[bm.RootID] = append(blocks, bm.ID)
}
}
historyDir, err := getHistoryDir(HistoryOpReplace, time.Now())
for treeID, blocks := range treeBlocks {
util.PushEndlessProgress("[" + treeID + "]")
tree, e := LoadTreeByBlockID(treeID)
@@ -53,6 +57,7 @@ func RemoveBookmark(bookmark string) (err error) {
return e
}
changed := false
for _, blockID := range blocks {
node := treenode.GetNodeInTree(tree, blockID)
if nil == node {
@@ -62,17 +67,25 @@ func RemoveBookmark(bookmark string) (err error) {
if bookmarkAttrVal := node.IALAttr("bookmark"); bookmarkAttrVal == bookmark {
node.RemoveIALAttr("bookmark")
cache.PutBlockIAL(node.ID, parse.IAL2Map(node.KramdownIAL))
changed = true
}
}
util.PushEndlessProgress(fmt.Sprintf(Conf.Language(111), util.EscapeHTML(tree.Root.IALAttr("title"))))
if err = writeTreeUpsertQueue(tree); err != nil {
util.ClearPushProgress(100)
return
if changed {
generateTreeHistory(historyDir, tree)
util.PushEndlessProgress(fmt.Sprintf(Conf.Language(111), util.EscapeHTML(tree.Root.IALAttr("title"))))
if err = writeTreeUpsertQueue(tree); err != nil {
util.ClearPushProgress(100)
return
}
}
util.RandomSleep(50, 150)
}
indexHistoryDir(filepath.Base(historyDir), util.NewLute())
sql.FlushQueue()
util.ReloadUI()
return
}
@@ -95,14 +108,15 @@ func RenameBookmark(oldBookmark, newBookmark string) (err error) {
bookmarks := sql.QueryBookmarkBlocks()
treeBlocks := map[string][]string{}
for _, tag := range bookmarks {
if blocks, ok := treeBlocks[tag.RootID]; !ok {
treeBlocks[tag.RootID] = []string{tag.ID}
for _, bm := range bookmarks {
if blocks, ok := treeBlocks[bm.RootID]; !ok {
treeBlocks[bm.RootID] = []string{bm.ID}
} else {
treeBlocks[tag.RootID] = append(blocks, tag.ID)
treeBlocks[bm.RootID] = append(blocks, bm.ID)
}
}
historyDir, err := getHistoryDir(HistoryOpReplace, time.Now())
for treeID, blocks := range treeBlocks {
util.PushEndlessProgress("[" + treeID + "]")
tree, e := LoadTreeByBlockID(treeID)
@@ -111,6 +125,7 @@ func RenameBookmark(oldBookmark, newBookmark string) (err error) {
return e
}
changed := false
for _, blockID := range blocks {
node := treenode.GetNodeInTree(tree, blockID)
if nil == node {
@@ -120,17 +135,25 @@ func RenameBookmark(oldBookmark, newBookmark string) (err error) {
if bookmarkAttrVal := node.IALAttr("bookmark"); bookmarkAttrVal == oldBookmark {
node.SetIALAttr("bookmark", newBookmark)
cache.PutBlockIAL(node.ID, parse.IAL2Map(node.KramdownIAL))
changed = true
}
}
util.PushEndlessProgress(fmt.Sprintf(Conf.Language(111), util.EscapeHTML(tree.Root.IALAttr("title"))))
if err = writeTreeUpsertQueue(tree); err != nil {
util.ClearPushProgress(100)
return
if changed {
generateTreeHistory(historyDir, tree)
util.PushEndlessProgress(fmt.Sprintf(Conf.Language(111), util.EscapeHTML(tree.Root.IALAttr("title"))))
if err = writeTreeUpsertQueue(tree); err != nil {
util.ClearPushProgress(100)
return
}
}
util.RandomSleep(50, 150)
}
indexHistoryDir(filepath.Base(historyDir), util.NewLute())
sql.FlushQueue()
util.ReloadUI()
return
}

View File

@@ -53,6 +53,8 @@ func RemoveTag(label string) (err error) {
var reloadTreeIDs []string
updateNodes := map[string]*ast.Node{}
historyDir, err := getHistoryDir(HistoryOpReplace, time.Now())
for treeID, blocks := range treeBlocks {
util.PushEndlessProgress("[" + treeID + "]")
tree, e := LoadTreeByBlockIDWithReindex(treeID)
@@ -61,6 +63,8 @@ func RemoveTag(label string) (err error) {
return e
}
generateTreeHistory(historyDir, tree)
var unlinks []*ast.Node
for _, blockID := range blocks {
node := treenode.GetNodeInTree(tree, blockID)
@@ -106,6 +110,7 @@ func RemoveTag(label string) (err error) {
reloadTreeIDs = append(reloadTreeIDs, tree.ID)
}
indexHistoryDir(filepath.Base(historyDir), util.NewLute())
sql.FlushQueue()
reloadTreeIDs = gulu.Str.RemoveDuplicatedElem(reloadTreeIDs)