This commit is contained in:
Daniel 2024-03-15 22:53:37 +08:00
parent 04b61dc7eb
commit 6feabe74c8
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
5 changed files with 13 additions and 19 deletions

View file

@ -170,7 +170,7 @@ func index(boxID string) {
cache.PutDocIAL(file.path, docIAL) cache.PutDocIAL(file.path, docIAL)
treenode.IndexBlockTree(tree) treenode.IndexBlockTree(tree)
sql.IndexTreeQueue(box.ID, file.path) sql.IndexTreeQueue(tree)
util.IncBootProgress(bootProgressPart, fmt.Sprintf(Conf.Language(92), util.ShortPathForBootingDisplay(tree.Path))) util.IncBootProgress(bootProgressPart, fmt.Sprintf(Conf.Language(92), util.ShortPathForBootingDisplay(tree.Path)))
if 1 < i && 0 == i%64 { if 1 < i && 0 == i%64 {
util.PushStatusBar(fmt.Sprintf(Conf.Language(88), i, (len(files))-i)) util.PushStatusBar(fmt.Sprintf(Conf.Language(88), i, (len(files))-i))

View file

@ -470,7 +470,7 @@ func reindexTree0(tree *parse.Tree, i, size int) {
indexWriteJSONQueue(tree) indexWriteJSONQueue(tree)
} else { } else {
treenode.IndexBlockTree(tree) treenode.IndexBlockTree(tree)
sql.IndexTreeQueue(tree.Box, tree.Path) sql.IndexTreeQueue(tree)
} }
if 0 == i%64 { if 0 == i%64 {

View file

@ -307,7 +307,7 @@ func removeIndexes(removeFilePaths []string) (removeRootIDs []string) {
util.PushStatusBar(msg) util.PushStatusBar(msg)
treenode.RemoveBlockTreesByRootID(block.RootID) treenode.RemoveBlockTreesByRootID(block.RootID)
sql.RemoveTreeQueue(block.BoxID, block.RootID) sql.RemoveTreeQueue(block.RootID)
} }
} }

View file

@ -40,10 +40,10 @@ var (
type dbQueueOperation struct { type dbQueueOperation struct {
inQueueTime time.Time inQueueTime time.Time
action string // upsert/delete/delete_id/rename/rename_sub_tree/delete_box/delete_box_refs/insert_refs/index/delete_ids/update_block_content/delete_assets action string // upsert/delete/delete_id/rename/rename_sub_tree/delete_box/delete_box_refs/insert_refs/index/delete_ids/update_block_content/delete_assets
indexPath string // index indexTree *parse.Tree // index
upsertTree *parse.Tree // upsert/insert_refs/update_refs/delete_refs upsertTree *parse.Tree // upsert/insert_refs/update_refs/delete_refs
removeTreeBox, removeTreePath string // delete removeTreeBox, removeTreePath string // delete
removeTreeIDBox, removeTreeID string // delete_id removeTreeID string // delete_id
removeTreeIDs []string // delete_ids removeTreeIDs []string // delete_ids
box string // delete_box/delete_box_refs/index box string // delete_box/delete_box_refs/index
renameTree *parse.Tree // rename/rename_sub_tree renameTree *parse.Tree // rename/rename_sub_tree
@ -164,7 +164,7 @@ func FlushQueue() {
func execOp(op *dbQueueOperation, tx *sql.Tx, context map[string]interface{}) (err error) { func execOp(op *dbQueueOperation, tx *sql.Tx, context map[string]interface{}) (err error) {
switch op.action { switch op.action {
case "index": case "index":
err = indexTree(tx, op.box, op.indexPath, context) err = indexTree(tx, op.indexTree, context)
case "upsert": case "upsert":
err = upsertTree(tx, op.upsertTree, context) err = upsertTree(tx, op.upsertTree, context)
case "delete": case "delete":
@ -315,13 +315,13 @@ func DeleteBoxQueue(boxID string) {
operationQueue = append(operationQueue, newOp) operationQueue = append(operationQueue, newOp)
} }
func IndexTreeQueue(box, p string) { func IndexTreeQueue(tree *parse.Tree) {
dbQueueLock.Lock() dbQueueLock.Lock()
defer dbQueueLock.Unlock() defer dbQueueLock.Unlock()
newOp := &dbQueueOperation{indexPath: p, box: box, inQueueTime: time.Now(), action: "index"} newOp := &dbQueueOperation{indexTree: tree, inQueueTime: time.Now(), action: "index"}
for i, op := range operationQueue { for i, op := range operationQueue {
if "index" == op.action && op.indexPath == p && op.box == box { // 相同树则覆盖 if "index" == op.action && op.indexTree.ID == tree.ID { // 相同树则覆盖
operationQueue[i] = newOp operationQueue[i] = newOp
return return
} }
@ -379,13 +379,13 @@ func RenameSubTreeQueue(tree *parse.Tree) {
operationQueue = append(operationQueue, newOp) operationQueue = append(operationQueue, newOp)
} }
func RemoveTreeQueue(box, rootID string) { func RemoveTreeQueue(rootID string) {
dbQueueLock.Lock() dbQueueLock.Lock()
defer dbQueueLock.Unlock() defer dbQueueLock.Unlock()
newOp := &dbQueueOperation{removeTreeIDBox: box, removeTreeID: rootID, inQueueTime: time.Now(), action: "delete_id"} newOp := &dbQueueOperation{removeTreeID: rootID, inQueueTime: time.Now(), action: "delete_id"}
for i, op := range operationQueue { for i, op := range operationQueue {
if "delete_id" == op.action && op.removeTreeIDBox == box && op.removeTreeID == rootID { if "delete_id" == op.action && op.removeTreeID == rootID {
operationQueue[i] = newOp operationQueue[i] = newOp
return return
} }

View file

@ -33,7 +33,6 @@ import (
ignore "github.com/sabhiram/go-gitignore" ignore "github.com/sabhiram/go-gitignore"
"github.com/siyuan-note/eventbus" "github.com/siyuan-note/eventbus"
"github.com/siyuan-note/logging" "github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/util" "github.com/siyuan-note/siyuan/kernel/util"
) )
@ -401,12 +400,7 @@ func insertRefs(tx *sql.Tx, tree *parse.Tree) (err error) {
return err return err
} }
func indexTree(tx *sql.Tx, box, p string, context map[string]interface{}) (err error) { func indexTree(tx *sql.Tx, tree *parse.Tree, context map[string]interface{}) (err error) {
tree, err := filesys.LoadTree(box, p, luteEngine)
if nil != err {
return
}
blocks, spans, assets, attributes := fromTree(tree.Root, tree) blocks, spans, assets, attributes := fromTree(tree.Root, tree)
refs, fileAnnotationRefs := refsFromTree(tree) refs, fileAnnotationRefs := refsFromTree(tree)
err = insertTree0(tx, tree, context, blocks, spans, assets, attributes, refs, fileAnnotationRefs) err = insertTree0(tx, tree, context, blocks, spans, assets, attributes, refs, fileAnnotationRefs)