Skip to content

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

:zap: Improve marketplace loading performance Fix https://github.com/siyuan-note/siyuan/issues/10973

Danielda59fa2afa6d
diff --git a/kernel/bazaar/icon.go b/kernel/bazaar/icon.go
index ffe18eecc4..94c669d519 100644
--- a/kernel/bazaar/icon.go
+++ b/kernel/bazaar/icon.go
@@ -51,6 +51,13 @@ func Icons() (icons []*Icon) {
repo := arg.(*StageRepo)
repoURL := repo.URL
+ if pkg, found := packageCache.Get(repoURL); found {
+ lock.Lock()
+ icons = append(icons, pkg.(*Icon))
+ lock.Unlock()
+ return
+ }
+
icon := &Icon{}
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/icon.json"
innerResp, innerErr := httpclient.NewBrowserRequest().SetSuccessResult(icon).Get(innerU)
@@ -91,6 +98,8 @@ func Icons() (icons []*Icon) {
lock.Lock()
icons = append(icons, icon)
lock.Unlock()
+
+ packageCache.SetDefault(repoURL, icon)
})
for _, repo := range stageIndex.Repos {
waitGroup.Add(1)
diff --git a/kernel/bazaar/package.go b/kernel/bazaar/package.go
index eb418177d1..f96161d4b6 100644
--- a/kernel/bazaar/package.go
+++ b/kernel/bazaar/package.go
@@ -29,6 +29,7 @@ import (
"github.com/88250/lute"
"github.com/araddon/dateparse"
"github.com/imroc/req/v3"
+ gcache "github.com/patrickmn/go-cache"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/httpclient"
"github.com/siyuan-note/logging"
@@ -680,3 +681,5 @@ func disallowDisplayBazaarPackage(pkg *Package) bool {
}
return false
}
+
+var packageCache = gcache.New(6*time.Hour, 30*time.Minute) // [repoURL]*Package
diff --git a/kernel/bazaar/plugin.go b/kernel/bazaar/plugin.go
index 66ffe35b66..0b70157ef5 100644
--- a/kernel/bazaar/plugin.go
+++ b/kernel/bazaar/plugin.go
@@ -55,6 +55,13 @@ func Plugins(frontend string) (plugins []*Plugin) {
repo := arg.(*StageRepo)
repoURL := repo.URL
+ if pkg, found := packageCache.Get(repoURL); found {
+ lock.Lock()
+ plugins = append(plugins, pkg.(*Plugin))
+ lock.Unlock()
+ return
+ }
+
plugin := &Plugin{}
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/plugin.json"
innerResp, innerErr := httpclient.NewBrowserRequest().SetSuccessResult(plugin).Get(innerU)
@@ -97,6 +104,8 @@ func Plugins(frontend string) (plugins []*Plugin) {
lock.Lock()
plugins = append(plugins, plugin)
lock.Unlock()
+
+ packageCache.SetDefault(repoURL, plugin)
})
for _, repo := range stageIndex.Repos {
waitGroup.Add(1)
diff --git a/kernel/bazaar/template.go b/kernel/bazaar/template.go
index a230782c10..ec5b130d81 100644
--- a/kernel/bazaar/template.go
+++ b/kernel/bazaar/template.go
@@ -53,6 +53,13 @@ func Templates() (templates []*Template) {
repo := arg.(*StageRepo)
repoURL := repo.URL
+ if pkg, found := packageCache.Get(repoURL); found {
+ lock.Lock()
+ templates = append(templates, pkg.(*Template))
+ lock.Unlock()
+ return
+ }
+
template := &Template{}
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/template.json"
innerResp, innerErr := httpclient.NewBrowserRequest().SetSuccessResult(template).Get(innerU)
@@ -93,6 +100,8 @@ func Templates() (templates []*Template) {
lock.Lock()
templates = append(templates, template)
lock.Unlock()
+
+ packageCache.SetDefault(repoURL, template)
})
for _, repo := range stageIndex.Repos {
waitGroup.Add(1)
diff --git a/kernel/bazaar/theme.go b/kernel/bazaar/theme.go
index 3906886c1b..1a32efdaa9 100644
--- a/kernel/bazaar/theme.go
+++ b/kernel/bazaar/theme.go
@@ -53,6 +53,13 @@ func Themes() (ret []*Theme) {
repo := arg.(*StageRepo)
repoURL := repo.URL
+ if pkg, found := packageCache.Get(repoURL); found {
+ lock.Lock()
+ ret = append(ret, pkg.(*Theme))
+ lock.Unlock()
+ return
+ }
+
theme := &Theme{}
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/theme.json"
innerResp, innerErr := httpclient.NewBrowserRequest().SetSuccessResult(theme).Get(innerU)
@@ -93,6 +100,8 @@ func Themes() (ret []*Theme) {
lock.Lock()
ret = append(ret, theme)
lock.Unlock()
+
+ packageCache.SetDefault(repoURL, theme)
})
for _, repo := range stageIndex.Repos {
waitGroup.Add(1)
diff --git a/kernel/bazaar/widget.go b/kernel/bazaar/widget.go
index 55643dc6d5..1d6d64e5dc 100644
--- a/kernel/bazaar/widget.go
+++ b/kernel/bazaar/widget.go
@@ -53,6 +53,13 @@ func Widgets() (widgets []*Widget) {
repo := arg.(*StageRepo)
repoURL := repo.URL
+ if pkg, found := packageCache.Get(repoURL); found {
+ lock.Lock()
+ widgets = append(widgets, pkg.(*Widget))
+ lock.Unlock()
+ return
+ }
+
widget := &Widget{}
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/widget.json"
innerResp, innerErr := httpclient.NewBrowserRequest().SetSuccessResult(widget).Get(innerU)
@@ -93,6 +100,8 @@ func Widgets() (widgets []*Widget) {
lock.Lock()
widgets = append(widgets, widget)
lock.Unlock()
+
+ packageCache.SetDefault(repoURL, widget)
})
for _, repo := range stageIndex.Repos {
waitGroup.Add(1)
diff --git a/kernel/model/cloud_service.go b/kernel/model/cloud_service.go
index dcbe38dd81..6092544149 100644
--- a/kernel/model/cloud_service.go
+++ b/kernel/model/cloud_service.go
@@ -210,6 +210,7 @@ var (
)
func RefreshCheckJob() {
+ go util.GetRhyResult(true) // 发一次请求进行结果缓存
go refreshSubscriptionExpirationRemind()
go refreshUser()
go refreshAnnouncement()