mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-28 19:26:09 +01:00
This commit is contained in:
parent
78ed38a33a
commit
df9122b664
16 changed files with 175 additions and 197 deletions
|
|
@ -56,17 +56,9 @@ type Box struct {
|
|||
historyGenerated int64 // 最近一次历史生成时间
|
||||
}
|
||||
|
||||
func AutoStat() {
|
||||
time.Sleep(time.Minute)
|
||||
autoStat()
|
||||
for range time.Tick(2 * time.Hour) {
|
||||
autoStat()
|
||||
}
|
||||
}
|
||||
|
||||
var statLock = sync.Mutex{}
|
||||
|
||||
func autoStat() {
|
||||
func StatJob() {
|
||||
statLock.Lock()
|
||||
defer statLock.Unlock()
|
||||
|
||||
|
|
|
|||
|
|
@ -187,13 +187,10 @@ func IndexRefs() {
|
|||
util.PushStatusBar(fmt.Sprintf(Conf.Language(55), i))
|
||||
}
|
||||
|
||||
// AutoIndexEmbedBlock 嵌入块支持搜索 https://github.com/siyuan-note/siyuan/issues/7112
|
||||
func AutoIndexEmbedBlock() {
|
||||
for {
|
||||
embedBlocks := sql.QueryEmptyContentEmbedBlocks()
|
||||
task.AppendTask(task.DatabaseIndexEmbedBlock, autoIndexEmbedBlock, embedBlocks)
|
||||
time.Sleep(10 * time.Minute)
|
||||
}
|
||||
// IndexEmbedBlockJob 嵌入块支持搜索 https://github.com/siyuan-note/siyuan/issues/7112
|
||||
func IndexEmbedBlockJob() {
|
||||
embedBlocks := sql.QueryEmptyContentEmbedBlocks()
|
||||
task.AppendTask(task.DatabaseIndexEmbedBlock, autoIndexEmbedBlock, embedBlocks)
|
||||
}
|
||||
|
||||
func autoIndexEmbedBlock(embedBlocks []*sql.Block) {
|
||||
|
|
|
|||
|
|
@ -36,12 +36,9 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
// AutoFixIndex 自动校验数据库索引 https://github.com/siyuan-note/siyuan/issues/7016
|
||||
func AutoFixIndex() {
|
||||
for {
|
||||
task.AppendTask(task.DatabaseIndexFix, autoFixIndex)
|
||||
time.Sleep(10 * time.Minute)
|
||||
}
|
||||
// FixIndexJob 自动校验数据库索引 https://github.com/siyuan-note/siyuan/issues/7016
|
||||
func FixIndexJob() {
|
||||
task.AppendTask(task.DatabaseIndexFix, autoFixIndex)
|
||||
}
|
||||
|
||||
var autoFixLock = sync.Mutex{}
|
||||
|
|
|
|||
|
|
@ -144,19 +144,14 @@ func LoadUploadToken() (err error) {
|
|||
}
|
||||
|
||||
var (
|
||||
refreshCheckTicker = time.NewTicker(2 * time.Hour)
|
||||
subscriptionExpirationReminded bool
|
||||
)
|
||||
|
||||
func AutoRefreshCheck() {
|
||||
for {
|
||||
go refreshSubscriptionExpirationRemind()
|
||||
go refreshUser()
|
||||
go refreshAnnouncement()
|
||||
go refreshCheckDownloadInstallPkg()
|
||||
|
||||
<-refreshCheckTicker.C
|
||||
}
|
||||
func RefreshCheckJob() {
|
||||
go refreshSubscriptionExpirationRemind()
|
||||
go refreshUser()
|
||||
go refreshAnnouncement()
|
||||
go refreshCheckDownloadInstallPkg()
|
||||
}
|
||||
|
||||
func refreshSubscriptionExpirationRemind() {
|
||||
|
|
|
|||
|
|
@ -19,15 +19,12 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func AutoOCRAssets() {
|
||||
func OCRAssetsJob() {
|
||||
if !util.TesseractEnabled {
|
||||
return
|
||||
}
|
||||
|
||||
for {
|
||||
task.AppendTask(task.OCRImage, autoOCRAssets)
|
||||
time.Sleep(7 * time.Second)
|
||||
}
|
||||
task.AppendTask(task.OCRImage, autoOCRAssets)
|
||||
}
|
||||
|
||||
func autoOCRAssets() {
|
||||
|
|
@ -111,11 +108,8 @@ func getUnOCRAssetsAbsPaths() (ret []string) {
|
|||
return
|
||||
}
|
||||
|
||||
func AutoFlushAssetsTexts() {
|
||||
for {
|
||||
SaveAssetsTexts()
|
||||
time.Sleep(7 * time.Second)
|
||||
}
|
||||
func FlushAssetsTextsJob() {
|
||||
SaveAssetsTexts()
|
||||
}
|
||||
|
||||
func LoadAssetsTexts() {
|
||||
|
|
|
|||
|
|
@ -37,45 +37,51 @@ func HandleSignal() {
|
|||
Close(false, 1)
|
||||
}
|
||||
|
||||
func HookDesktopUIProc() {
|
||||
var firstRunHookDesktopUIProcJob = true
|
||||
|
||||
func HookDesktopUIProcJob() {
|
||||
if util.ContainerStd != util.Container || "dev" == util.Mode {
|
||||
return
|
||||
}
|
||||
|
||||
time.Sleep(30 * time.Second)
|
||||
if firstRunHookDesktopUIProcJob {
|
||||
// 等待启动结束再
|
||||
time.Sleep(30 * time.Second)
|
||||
firstRunHookDesktopUIProcJob = false
|
||||
return
|
||||
}
|
||||
|
||||
uiProcNames := []string{"siyuan", "electron"}
|
||||
existUIProc := false
|
||||
for range time.Tick(7 * time.Second) {
|
||||
util.UIProcessIDs.Range(func(uiProcIDArg, _ interface{}) bool {
|
||||
uiProcID, err := strconv.Atoi(uiProcIDArg.(string))
|
||||
if nil != err {
|
||||
logging.LogErrorf("invalid UI proc ID [%s]: %s", uiProcIDArg, err)
|
||||
return true
|
||||
}
|
||||
|
||||
proc, err := goPS.FindProcess(uiProcID)
|
||||
if nil != err {
|
||||
logging.LogErrorf("find UI proc [%d] failed: %s", uiProcID, err)
|
||||
return true
|
||||
}
|
||||
|
||||
if nil == proc {
|
||||
return true
|
||||
}
|
||||
|
||||
procName := strings.ToLower(proc.Executable())
|
||||
for _, name := range uiProcNames {
|
||||
if strings.Contains(procName, name) {
|
||||
existUIProc = true
|
||||
return false
|
||||
}
|
||||
}
|
||||
util.UIProcessIDs.Range(func(uiProcIDArg, _ interface{}) bool {
|
||||
uiProcID, err := strconv.Atoi(uiProcIDArg.(string))
|
||||
if nil != err {
|
||||
logging.LogErrorf("invalid UI proc ID [%s]: %s", uiProcIDArg, err)
|
||||
return true
|
||||
})
|
||||
|
||||
if !existUIProc {
|
||||
logging.LogInfof("no active UI proc, exit kernel process now")
|
||||
Close(false, 1)
|
||||
}
|
||||
|
||||
proc, err := goPS.FindProcess(uiProcID)
|
||||
if nil != err {
|
||||
logging.LogErrorf("find UI proc [%d] failed: %s", uiProcID, err)
|
||||
return true
|
||||
}
|
||||
|
||||
if nil == proc {
|
||||
return true
|
||||
}
|
||||
|
||||
procName := strings.ToLower(proc.Executable())
|
||||
for _, name := range uiProcNames {
|
||||
if strings.Contains(procName, name) {
|
||||
existUIProc = true
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
if !existUIProc {
|
||||
logging.LogInfof("no active UI proc, exit kernel process now")
|
||||
Close(false, 1)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,12 +46,9 @@ var (
|
|||
ExitSyncSucc = -1
|
||||
)
|
||||
|
||||
func AutoSync() {
|
||||
for {
|
||||
time.Sleep(5 * time.Second)
|
||||
if time.Now().After(syncPlanTime) {
|
||||
SyncData(false, false, false)
|
||||
}
|
||||
func SyncDataJob() {
|
||||
if time.Now().After(syncPlanTime) {
|
||||
SyncData(false, false, false)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,7 +66,6 @@ const txFixDelay = 10
|
|||
var (
|
||||
txQueue []*Transaction
|
||||
txQueueLock = sync.Mutex{}
|
||||
txDelay = txFixDelay
|
||||
|
||||
currentTx *Transaction
|
||||
)
|
||||
|
|
@ -88,19 +87,15 @@ func WaitForWritingFiles() {
|
|||
}
|
||||
|
||||
func isWritingFiles() bool {
|
||||
time.Sleep(time.Duration(txDelay+5) * time.Millisecond)
|
||||
time.Sleep(time.Duration(txFixDelay+10) * time.Millisecond)
|
||||
if 0 < len(txQueue) || util.IsMutexLocked(&txQueueLock) {
|
||||
return true
|
||||
}
|
||||
return nil != currentTx
|
||||
}
|
||||
|
||||
func AutoFlushTx() {
|
||||
go autoFlushUpdateRefTextRenameDoc()
|
||||
for {
|
||||
flushTx()
|
||||
time.Sleep(time.Duration(txDelay) * time.Millisecond)
|
||||
}
|
||||
func FlushTxJob() {
|
||||
flushTx()
|
||||
}
|
||||
|
||||
func flushTx() {
|
||||
|
|
@ -123,7 +118,7 @@ func flushTx() {
|
|||
elapsed := time.Now().Sub(start).Milliseconds()
|
||||
if 0 < len(currentTx.DoOperations) {
|
||||
if 2000 < elapsed {
|
||||
logging.LogWarnf("tx [%dms]", elapsed)
|
||||
logging.LogWarnf("op tx [%dms]", elapsed)
|
||||
}
|
||||
}
|
||||
currentTx = nil
|
||||
|
|
@ -178,12 +173,6 @@ type TxErr struct {
|
|||
|
||||
func performTx(tx *Transaction) (ret *TxErr) {
|
||||
if 1 > len(tx.DoOperations) {
|
||||
txDelay -= 1000
|
||||
if 100*txFixDelay < txDelay {
|
||||
txDelay = txDelay / 2
|
||||
} else if 0 > txDelay {
|
||||
txDelay = txFixDelay
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -202,7 +191,6 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
|||
return
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
for _, op := range tx.DoOperations {
|
||||
switch op.Action {
|
||||
case "create":
|
||||
|
|
@ -243,11 +231,6 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
|||
logging.LogErrorf("commit tx failed: %s", cr)
|
||||
return &TxErr{msg: cr.Error()}
|
||||
}
|
||||
elapsed := int(time.Now().Sub(start).Milliseconds())
|
||||
txDelay = 10 + elapsed
|
||||
if 1000*10 < txDelay {
|
||||
txDelay = 1000 * 10
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -1186,11 +1169,9 @@ func updateRefTextRenameDoc(renamedTree *parse.Tree) {
|
|||
updateRefTextRenameDocLock.Unlock()
|
||||
}
|
||||
|
||||
func autoFlushUpdateRefTextRenameDoc() {
|
||||
for {
|
||||
sql.WaitForWritingDatabase()
|
||||
flushUpdateRefTextRenameDoc()
|
||||
}
|
||||
func FlushUpdateRefTextRenameDocJob() {
|
||||
sql.WaitForWritingDatabase()
|
||||
flushUpdateRefTextRenameDoc()
|
||||
}
|
||||
|
||||
func flushUpdateRefTextRenameDoc() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue