🎨 Improve rhy cache duration

Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2026-01-04 11:50:40 +08:00
parent 79e7339517
commit 535308f6ab
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
4 changed files with 16 additions and 9 deletions

View file

@ -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
}

View file

@ -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)

View file

@ -214,10 +214,13 @@ var (
subscriptionExpirationReminded bool
)
func RefreshCheckJob() {
func RefreshCheckJob2H() {
go refreshSubscriptionExpirationRemind()
go refreshUser()
go refreshAnnouncement()
}
func RefreshCheckJob6H() {
go refreshCheckDownloadInstallPkg()
}

View file

@ -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
}