From 535308f6ab90b1921ddcb18f2caf677963499162 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sun, 4 Jan 2026 11:50:40 +0800 Subject: [PATCH] :art: Improve rhy cache duration Signed-off-by: Daniel <845765@qq.com> --- kernel/bazaar/package.go | 2 +- kernel/job/cron.go | 3 ++- kernel/model/cloud_service.go | 5 ++++- kernel/util/rhy.go | 15 +++++++++------ 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/kernel/bazaar/package.go b/kernel/bazaar/package.go index 85a132e36..cae1efc29 100644 --- a/kernel/bazaar/package.go +++ b/kernel/bazaar/package.go @@ -575,7 +575,7 @@ func getStageIndex(pkgType string) (ret *StageIndex, err error) { defer stageIndexLock.Unlock() now := time.Now().Unix() - if 3600 >= now-stageIndexCacheTime && nil != cachedStageIndex[pkgType] { + if util.RhyCacheDuration >= now-stageIndexCacheTime && nil != cachedStageIndex[pkgType] { ret = cachedStageIndex[pkgType] return } diff --git a/kernel/job/cron.go b/kernel/job/cron.go index 2610cae76..075c7bc49 100644 --- a/kernel/job/cron.go +++ b/kernel/job/cron.go @@ -33,7 +33,8 @@ func StartCron() { go every(5*time.Second, model.SyncDataJob) go every(2*time.Hour, model.StatJob) go every(6*time.Hour, util.RefreshRhyResultJob, "RefreshRhyResultJob") - go every(2*time.Hour, model.RefreshCheckJob) + go every(2*time.Hour, model.RefreshCheckJob2H) + go every(6*time.Hour, model.RefreshCheckJob6H) go every(3*time.Second, model.FlushUpdateRefTextRenameDocJob) go every(util.SQLFlushInterval, sql.FlushTxJob) go every(util.SQLFlushInterval, sql.FlushHistoryTxJob) diff --git a/kernel/model/cloud_service.go b/kernel/model/cloud_service.go index 9b9a14c65..6e4c7e8b2 100644 --- a/kernel/model/cloud_service.go +++ b/kernel/model/cloud_service.go @@ -214,10 +214,13 @@ var ( subscriptionExpirationReminded bool ) -func RefreshCheckJob() { +func RefreshCheckJob2H() { go refreshSubscriptionExpirationRemind() go refreshUser() go refreshAnnouncement() +} + +func RefreshCheckJob6H() { go refreshCheckDownloadInstallPkg() } diff --git a/kernel/util/rhy.go b/kernel/util/rhy.go index bbb37ac92..bca7d8b54 100644 --- a/kernel/util/rhy.go +++ b/kernel/util/rhy.go @@ -26,21 +26,24 @@ import ( "github.com/siyuan-note/logging" ) -var cachedRhyResult = map[string]interface{}{} -var rhyResultCacheTime int64 -var rhyResultLock = sync.Mutex{} +var ( + RhyCacheDuration = int64(3600 * 6) + + cachedRhyResult = map[string]interface{}{} + rhyResultCacheTime int64 + rhyResultLock = sync.Mutex{} +) func GetRhyResult(force bool) (map[string]interface{}, error) { rhyResultLock.Lock() defer rhyResultLock.Unlock() - cacheDuration := int64(3600 * 6) if ContainerDocker == Container { - cacheDuration = int64(3600 * 24) + RhyCacheDuration = int64(3600 * 24) } now := time.Now().Unix() - if cacheDuration >= now-rhyResultCacheTime && !force && 0 < len(cachedRhyResult) { + if RhyCacheDuration >= now-rhyResultCacheTime && !force && 0 < len(cachedRhyResult) { return cachedRhyResult, nil }