mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 Prevent frontend request pending https://github.com/siyuan-note/siyuan/issues/10992
This commit is contained in:
parent
f822e4d69e
commit
ee473289d2
3 changed files with 32 additions and 23 deletions
|
|
@ -35,6 +35,7 @@ import (
|
|||
var (
|
||||
operationQueue []*dbQueueOperation
|
||||
dbQueueLock = sync.Mutex{}
|
||||
txLock = sync.Mutex{}
|
||||
)
|
||||
|
||||
type dbQueueOperation struct {
|
||||
|
|
@ -95,29 +96,30 @@ func ClearQueue() {
|
|||
}
|
||||
|
||||
func FlushQueue() {
|
||||
dbQueueLock.Lock()
|
||||
defer dbQueueLock.Unlock()
|
||||
|
||||
total := len(operationQueue)
|
||||
ops := getOperations()
|
||||
total := len(ops)
|
||||
if 1 > total {
|
||||
return
|
||||
}
|
||||
|
||||
txLock.Lock()
|
||||
defer txLock.Unlock()
|
||||
|
||||
start := time.Now()
|
||||
|
||||
context := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}
|
||||
if 512 < total {
|
||||
if 512 < len(ops) {
|
||||
disableCache()
|
||||
defer enableCache()
|
||||
}
|
||||
|
||||
groupOpsTotal := map[string]int{}
|
||||
for _, op := range operationQueue {
|
||||
for _, op := range ops {
|
||||
groupOpsTotal[op.action]++
|
||||
}
|
||||
|
||||
groupOpsCurrent := map[string]int{}
|
||||
for i, op := range operationQueue {
|
||||
for i, op := range ops {
|
||||
if util.IsExiting.Load() {
|
||||
return
|
||||
}
|
||||
|
|
@ -150,8 +152,6 @@ func FlushQueue() {
|
|||
debug.FreeOSMemory()
|
||||
}
|
||||
|
||||
operationQueue = nil
|
||||
|
||||
elapsed := time.Now().Sub(start).Milliseconds()
|
||||
if 7000 < elapsed {
|
||||
logging.LogInfof("database op tx [%dms]", elapsed)
|
||||
|
|
@ -418,3 +418,12 @@ func RemoveTreePathQueue(treeBox, treePathPrefix string) {
|
|||
}
|
||||
operationQueue = append(operationQueue, newOp)
|
||||
}
|
||||
|
||||
func getOperations() (ops []*dbQueueOperation) {
|
||||
dbQueueLock.Lock()
|
||||
defer dbQueueLock.Unlock()
|
||||
|
||||
ops = operationQueue
|
||||
operationQueue = nil
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue