mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 15:40:12 +01:00
⚡ Improve performance for data indexing https://github.com/siyuan-note/siyuan/issues/12777
This commit is contained in:
parent
2da4a885ef
commit
475155b7df
14 changed files with 17 additions and 62 deletions
|
|
@ -364,7 +364,7 @@ func TransferBlockRef(fromID, toID string, refIDs []string) (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sql.WaitForWritingDatabase()
|
sql.FlushQueue()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -191,9 +191,7 @@ func setNodeAttrs(node *ast.Node, tree *parse.Tree, nameValues map[string]string
|
||||||
pushBroadcastAttrTransactions(oldAttrs, node)
|
pushBroadcastAttrTransactions(oldAttrs, node)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
if !sql.IsEmptyQueue() {
|
sql.FlushQueue()
|
||||||
sql.WaitForWritingDatabase()
|
|
||||||
}
|
|
||||||
refreshDynamicRefText(node, tree)
|
refreshDynamicRefText(node, tree)
|
||||||
}()
|
}()
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -159,9 +159,7 @@ func BookmarkLabels() (ret []string) {
|
||||||
|
|
||||||
func BuildBookmark() (ret *Bookmarks) {
|
func BuildBookmark() (ret *Bookmarks) {
|
||||||
WaitForWritingFiles()
|
WaitForWritingFiles()
|
||||||
if !sql.IsEmptyQueue() {
|
sql.FlushQueue()
|
||||||
sql.WaitForWritingDatabase()
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = &Bookmarks{}
|
ret = &Bookmarks{}
|
||||||
sqlBlocks := sql.QueryBookmarkBlocks()
|
sqlBlocks := sql.QueryBookmarkBlocks()
|
||||||
|
|
|
||||||
|
|
@ -606,7 +606,7 @@ func FullReindex() {
|
||||||
task.AppendTask(task.DatabaseIndexFull, fullReindex)
|
task.AppendTask(task.DatabaseIndexFull, fullReindex)
|
||||||
task.AppendTask(task.DatabaseIndexRef, IndexRefs)
|
task.AppendTask(task.DatabaseIndexRef, IndexRefs)
|
||||||
go func() {
|
go func() {
|
||||||
sql.WaitForWritingDatabase()
|
sql.FlushQueue()
|
||||||
ResetVirtualBlockRefCache()
|
ResetVirtualBlockRefCache()
|
||||||
}()
|
}()
|
||||||
task.AppendTaskWithTimeout(task.DatabaseIndexEmbedBlock, 30*time.Second, autoIndexEmbedBlock)
|
task.AppendTaskWithTimeout(task.DatabaseIndexEmbedBlock, 30*time.Second, autoIndexEmbedBlock)
|
||||||
|
|
|
||||||
|
|
@ -612,7 +612,7 @@ func Close(force, setCurrentWorkspace bool, execInstallPkg int) (exitCode int) {
|
||||||
closeUserGuide()
|
closeUserGuide()
|
||||||
|
|
||||||
// Improve indexing completeness when exiting https://github.com/siyuan-note/siyuan/issues/12039
|
// Improve indexing completeness when exiting https://github.com/siyuan-note/siyuan/issues/12039
|
||||||
sql.WaitForWritingDatabaseIn(200 * time.Millisecond)
|
sql.FlushQueue()
|
||||||
|
|
||||||
util.IsExiting.Store(true)
|
util.IsExiting.Store(true)
|
||||||
waitSecondForExecInstallPkg := false
|
waitSecondForExecInstallPkg := false
|
||||||
|
|
|
||||||
|
|
@ -295,7 +295,7 @@ func RollbackDocHistory(boxID, historyPath string) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
sql.WaitForWritingDatabase()
|
sql.FlushQueue()
|
||||||
|
|
||||||
tree, _ = LoadTreeByBlockID(id)
|
tree, _ = LoadTreeByBlockID(id)
|
||||||
if nil == tree {
|
if nil == tree {
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ func listSyFiles(dir string) (ret []string) {
|
||||||
func (box *Box) Unindex() {
|
func (box *Box) Unindex() {
|
||||||
task.AppendTask(task.DatabaseIndex, unindex, box.ID)
|
task.AppendTask(task.DatabaseIndex, unindex, box.ID)
|
||||||
go func() {
|
go func() {
|
||||||
sql.WaitForWritingDatabase()
|
sql.FlushQueue()
|
||||||
ResetVirtualBlockRefCache()
|
ResetVirtualBlockRefCache()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
@ -123,7 +123,7 @@ func (box *Box) Index() {
|
||||||
task.AppendTask(task.DatabaseIndex, index, box.ID)
|
task.AppendTask(task.DatabaseIndex, index, box.ID)
|
||||||
task.AppendTask(task.DatabaseIndexRef, IndexRefs)
|
task.AppendTask(task.DatabaseIndexRef, IndexRefs)
|
||||||
go func() {
|
go func() {
|
||||||
sql.WaitForWritingDatabase()
|
sql.FlushQueue()
|
||||||
ResetVirtualBlockRefCache()
|
ResetVirtualBlockRefCache()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,15 +50,15 @@ func checkIndex() {
|
||||||
logging.LogInfof("start checking index...")
|
logging.LogInfof("start checking index...")
|
||||||
|
|
||||||
task.AppendTask(task.DatabaseIndexFix, removeDuplicateDatabaseIndex)
|
task.AppendTask(task.DatabaseIndexFix, removeDuplicateDatabaseIndex)
|
||||||
sql.WaitForWritingDatabase()
|
sql.FlushQueue()
|
||||||
|
|
||||||
task.AppendTask(task.DatabaseIndexFix, resetDuplicateBlocksOnFileSys)
|
task.AppendTask(task.DatabaseIndexFix, resetDuplicateBlocksOnFileSys)
|
||||||
|
|
||||||
task.AppendTask(task.DatabaseIndexFix, fixBlockTreeByFileSys)
|
task.AppendTask(task.DatabaseIndexFix, fixBlockTreeByFileSys)
|
||||||
sql.WaitForWritingDatabase()
|
sql.FlushQueue()
|
||||||
|
|
||||||
task.AppendTask(task.DatabaseIndexFix, fixDatabaseIndexByBlockTree)
|
task.AppendTask(task.DatabaseIndexFix, fixDatabaseIndexByBlockTree)
|
||||||
sql.WaitForWritingDatabase()
|
sql.FlushQueue()
|
||||||
|
|
||||||
task.AppendTask(task.DatabaseIndexFix, removeDuplicateDatabaseRefs)
|
task.AppendTask(task.DatabaseIndexFix, removeDuplicateDatabaseRefs)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -140,7 +140,7 @@ func refreshProtyle(rootID string) {
|
||||||
|
|
||||||
// refreshRefCount 用于刷新定义块处的引用计数。
|
// refreshRefCount 用于刷新定义块处的引用计数。
|
||||||
func refreshRefCount(rootID, blockID string) {
|
func refreshRefCount(rootID, blockID string) {
|
||||||
sql.WaitForWritingDatabase()
|
sql.FlushQueue()
|
||||||
|
|
||||||
bt := treenode.GetBlockTree(blockID)
|
bt := treenode.GetBlockTree(blockID)
|
||||||
if nil == bt {
|
if nil == bt {
|
||||||
|
|
|
||||||
|
|
@ -660,7 +660,7 @@ func checkoutRepo(id string) {
|
||||||
task.AppendTask(task.DatabaseIndexFull, fullReindex)
|
task.AppendTask(task.DatabaseIndexFull, fullReindex)
|
||||||
task.AppendTask(task.DatabaseIndexRef, IndexRefs)
|
task.AppendTask(task.DatabaseIndexRef, IndexRefs)
|
||||||
go func() {
|
go func() {
|
||||||
sql.WaitForWritingDatabase()
|
sql.FlushQueue()
|
||||||
ResetVirtualBlockRefCache()
|
ResetVirtualBlockRefCache()
|
||||||
}()
|
}()
|
||||||
task.AppendTask(task.ReloadUI, util.ReloadUIResetScroll)
|
task.AppendTask(task.ReloadUI, util.ReloadUIResetScroll)
|
||||||
|
|
|
||||||
|
|
@ -791,14 +791,14 @@ func FindReplace(keyword, replacement string, replaceTypes map[string]bool, ids
|
||||||
util.PushEndlessProgress(fmt.Sprintf(Conf.Language(207), i+1, len(renameRoots)))
|
util.PushEndlessProgress(fmt.Sprintf(Conf.Language(207), i+1, len(renameRoots)))
|
||||||
}
|
}
|
||||||
|
|
||||||
sql.WaitForWritingDatabase()
|
sql.FlushQueue()
|
||||||
|
|
||||||
reloadTreeIDs = gulu.Str.RemoveDuplicatedElem(reloadTreeIDs)
|
reloadTreeIDs = gulu.Str.RemoveDuplicatedElem(reloadTreeIDs)
|
||||||
for _, id := range reloadTreeIDs {
|
for _, id := range reloadTreeIDs {
|
||||||
refreshProtyle(id)
|
refreshProtyle(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
sql.WaitForWritingDatabase()
|
sql.FlushQueue()
|
||||||
util.PushClearProgress()
|
util.PushClearProgress()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -207,10 +207,7 @@ type Tags []*Tag
|
||||||
|
|
||||||
func BuildTags() (ret *Tags) {
|
func BuildTags() (ret *Tags) {
|
||||||
WaitForWritingFiles()
|
WaitForWritingFiles()
|
||||||
|
sql.FlushQueue()
|
||||||
if !sql.IsEmptyQueue() {
|
|
||||||
sql.WaitForWritingDatabase()
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = &Tags{}
|
ret = &Tags{}
|
||||||
labels := labelTags()
|
labels := labelTags()
|
||||||
|
|
|
||||||
|
|
@ -1532,7 +1532,7 @@ func updateRefTextRenameDoc(renamedTree *parse.Tree) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func FlushUpdateRefTextRenameDocJob() {
|
func FlushUpdateRefTextRenameDocJob() {
|
||||||
sql.WaitForWritingDatabase()
|
sql.FlushQueue()
|
||||||
flushUpdateRefTextRenameDoc()
|
flushUpdateRefTextRenameDoc()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,44 +58,6 @@ func FlushTxJob() {
|
||||||
task.AppendTask(task.DatabaseIndexCommit, FlushQueue)
|
task.AppendTask(task.DatabaseIndexCommit, FlushQueue)
|
||||||
}
|
}
|
||||||
|
|
||||||
func WaitForWritingDatabase() {
|
|
||||||
var printLog bool
|
|
||||||
var lastPrintLog bool
|
|
||||||
for i := 0; isWritingDatabase(util.SQLFlushInterval + 50*time.Millisecond); i++ {
|
|
||||||
time.Sleep(50 * time.Millisecond)
|
|
||||||
if 200 < i && !printLog { // 10s 后打日志
|
|
||||||
logging.LogWarnf("database is writing: \n%s", logging.ShortStack())
|
|
||||||
printLog = true
|
|
||||||
}
|
|
||||||
if 1200 < i && !lastPrintLog { // 60s 后打日志
|
|
||||||
logging.LogWarnf("database is still writing")
|
|
||||||
lastPrintLog = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WaitForWritingDatabaseIn(duration time.Duration) {
|
|
||||||
for i := 0; isWritingDatabase(duration); i++ {
|
|
||||||
time.Sleep(50 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func isWritingDatabase(d time.Duration) bool {
|
|
||||||
time.Sleep(d)
|
|
||||||
dbQueueLock.Lock()
|
|
||||||
defer dbQueueLock.Unlock()
|
|
||||||
if 0 < len(operationQueue) || isWriting {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func IsEmptyQueue() bool {
|
|
||||||
dbQueueLock.Lock()
|
|
||||||
defer dbQueueLock.Unlock()
|
|
||||||
return 1 > len(operationQueue)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ClearQueue() {
|
func ClearQueue() {
|
||||||
dbQueueLock.Lock()
|
dbQueueLock.Lock()
|
||||||
defer dbQueueLock.Unlock()
|
defer dbQueueLock.Unlock()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue