Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:sparkles: Shorthands on mobile https://github.com/siyuan-note/siyuan/issues/14414

Daniel380fcd7ed0a3
diff --git a/kernel/job/cron.go b/kernel/job/cron.go
index 8d583f7f3d..7a00475e16 100644
--- a/kernel/job/cron.go
+++ b/kernel/job/cron.go
@@ -48,7 +48,7 @@ func StartCron() {
go every(30*time.Minute, model.AutoCheckMicrosoftDefenderJob)
go every(24*time.Hour, model.ClearOutdatedHistoryDirJob)
if util.IsMobileContainer() {
- go every(7*time.Second, model.AutoConsumeShorthandsJob)
+ go every(3*time.Second, model.AutoConsumeShorthandsJob)
}
model.StartPushQueueConsumer()
diff --git a/kernel/model/shortcuts.go b/kernel/model/shortcuts.go
index 8b0d73390c..80a5b16c3a 100644
--- a/kernel/model/shortcuts.go
+++ b/kernel/model/shortcuts.go
@@ -23,6 +23,7 @@ import (
"slices"
"strconv"
"strings"
+ "sync"
"time"
"github.com/88250/gulu"
@@ -202,11 +203,18 @@ func MoveLocalShorthands(boxID string) (retIDs []string, err error) {
return
}
+var consumeShorthandsLock = sync.Mutex{}
+
func consumeShorthands() {
if !util.IsMobileContainer() {
return
}
+ // 消费速记涉及读取临时文件、创建/追加文档、删除临时文件等非原子操作,
+ // 启动同步、同步流程、定时任务都可能并发调用,这里串行化避免重复消费或丢失
+ consumeShorthandsLock.Lock()
+ defer consumeShorthandsLock.Unlock()
+
defer logging.Recover()
shorthandsDir := filepath.Join(util.ShortcutsPath, "shorthands")
@@ -258,9 +266,5 @@ func consumeShorthands() {
}
func AutoConsumeShorthandsJob() {
- if Conf.Sync.Enabled {
- return
- }
-
consumeShorthands()
}