mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
⚡ Improve marketplace loading performance Fix https://github.com/siyuan-note/siyuan/issues/10973
This commit is contained in:
parent
541483ed29
commit
da59fa2afa
7 changed files with 49 additions and 0 deletions
|
|
@ -51,6 +51,13 @@ func Icons() (icons []*Icon) {
|
||||||
repo := arg.(*StageRepo)
|
repo := arg.(*StageRepo)
|
||||||
repoURL := repo.URL
|
repoURL := repo.URL
|
||||||
|
|
||||||
|
if pkg, found := packageCache.Get(repoURL); found {
|
||||||
|
lock.Lock()
|
||||||
|
icons = append(icons, pkg.(*Icon))
|
||||||
|
lock.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
icon := &Icon{}
|
icon := &Icon{}
|
||||||
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/icon.json"
|
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/icon.json"
|
||||||
innerResp, innerErr := httpclient.NewBrowserRequest().SetSuccessResult(icon).Get(innerU)
|
innerResp, innerErr := httpclient.NewBrowserRequest().SetSuccessResult(icon).Get(innerU)
|
||||||
|
|
@ -91,6 +98,8 @@ func Icons() (icons []*Icon) {
|
||||||
lock.Lock()
|
lock.Lock()
|
||||||
icons = append(icons, icon)
|
icons = append(icons, icon)
|
||||||
lock.Unlock()
|
lock.Unlock()
|
||||||
|
|
||||||
|
packageCache.SetDefault(repoURL, icon)
|
||||||
})
|
})
|
||||||
for _, repo := range stageIndex.Repos {
|
for _, repo := range stageIndex.Repos {
|
||||||
waitGroup.Add(1)
|
waitGroup.Add(1)
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ import (
|
||||||
"github.com/88250/lute"
|
"github.com/88250/lute"
|
||||||
"github.com/araddon/dateparse"
|
"github.com/araddon/dateparse"
|
||||||
"github.com/imroc/req/v3"
|
"github.com/imroc/req/v3"
|
||||||
|
gcache "github.com/patrickmn/go-cache"
|
||||||
"github.com/siyuan-note/filelock"
|
"github.com/siyuan-note/filelock"
|
||||||
"github.com/siyuan-note/httpclient"
|
"github.com/siyuan-note/httpclient"
|
||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
|
|
@ -680,3 +681,5 @@ func disallowDisplayBazaarPackage(pkg *Package) bool {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var packageCache = gcache.New(6*time.Hour, 30*time.Minute) // [repoURL]*Package
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,13 @@ func Plugins(frontend string) (plugins []*Plugin) {
|
||||||
repo := arg.(*StageRepo)
|
repo := arg.(*StageRepo)
|
||||||
repoURL := repo.URL
|
repoURL := repo.URL
|
||||||
|
|
||||||
|
if pkg, found := packageCache.Get(repoURL); found {
|
||||||
|
lock.Lock()
|
||||||
|
plugins = append(plugins, pkg.(*Plugin))
|
||||||
|
lock.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
plugin := &Plugin{}
|
plugin := &Plugin{}
|
||||||
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/plugin.json"
|
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/plugin.json"
|
||||||
innerResp, innerErr := httpclient.NewBrowserRequest().SetSuccessResult(plugin).Get(innerU)
|
innerResp, innerErr := httpclient.NewBrowserRequest().SetSuccessResult(plugin).Get(innerU)
|
||||||
|
|
@ -97,6 +104,8 @@ func Plugins(frontend string) (plugins []*Plugin) {
|
||||||
lock.Lock()
|
lock.Lock()
|
||||||
plugins = append(plugins, plugin)
|
plugins = append(plugins, plugin)
|
||||||
lock.Unlock()
|
lock.Unlock()
|
||||||
|
|
||||||
|
packageCache.SetDefault(repoURL, plugin)
|
||||||
})
|
})
|
||||||
for _, repo := range stageIndex.Repos {
|
for _, repo := range stageIndex.Repos {
|
||||||
waitGroup.Add(1)
|
waitGroup.Add(1)
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,13 @@ func Templates() (templates []*Template) {
|
||||||
repo := arg.(*StageRepo)
|
repo := arg.(*StageRepo)
|
||||||
repoURL := repo.URL
|
repoURL := repo.URL
|
||||||
|
|
||||||
|
if pkg, found := packageCache.Get(repoURL); found {
|
||||||
|
lock.Lock()
|
||||||
|
templates = append(templates, pkg.(*Template))
|
||||||
|
lock.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
template := &Template{}
|
template := &Template{}
|
||||||
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/template.json"
|
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/template.json"
|
||||||
innerResp, innerErr := httpclient.NewBrowserRequest().SetSuccessResult(template).Get(innerU)
|
innerResp, innerErr := httpclient.NewBrowserRequest().SetSuccessResult(template).Get(innerU)
|
||||||
|
|
@ -93,6 +100,8 @@ func Templates() (templates []*Template) {
|
||||||
lock.Lock()
|
lock.Lock()
|
||||||
templates = append(templates, template)
|
templates = append(templates, template)
|
||||||
lock.Unlock()
|
lock.Unlock()
|
||||||
|
|
||||||
|
packageCache.SetDefault(repoURL, template)
|
||||||
})
|
})
|
||||||
for _, repo := range stageIndex.Repos {
|
for _, repo := range stageIndex.Repos {
|
||||||
waitGroup.Add(1)
|
waitGroup.Add(1)
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,13 @@ func Themes() (ret []*Theme) {
|
||||||
repo := arg.(*StageRepo)
|
repo := arg.(*StageRepo)
|
||||||
repoURL := repo.URL
|
repoURL := repo.URL
|
||||||
|
|
||||||
|
if pkg, found := packageCache.Get(repoURL); found {
|
||||||
|
lock.Lock()
|
||||||
|
ret = append(ret, pkg.(*Theme))
|
||||||
|
lock.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
theme := &Theme{}
|
theme := &Theme{}
|
||||||
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/theme.json"
|
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/theme.json"
|
||||||
innerResp, innerErr := httpclient.NewBrowserRequest().SetSuccessResult(theme).Get(innerU)
|
innerResp, innerErr := httpclient.NewBrowserRequest().SetSuccessResult(theme).Get(innerU)
|
||||||
|
|
@ -93,6 +100,8 @@ func Themes() (ret []*Theme) {
|
||||||
lock.Lock()
|
lock.Lock()
|
||||||
ret = append(ret, theme)
|
ret = append(ret, theme)
|
||||||
lock.Unlock()
|
lock.Unlock()
|
||||||
|
|
||||||
|
packageCache.SetDefault(repoURL, theme)
|
||||||
})
|
})
|
||||||
for _, repo := range stageIndex.Repos {
|
for _, repo := range stageIndex.Repos {
|
||||||
waitGroup.Add(1)
|
waitGroup.Add(1)
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,13 @@ func Widgets() (widgets []*Widget) {
|
||||||
repo := arg.(*StageRepo)
|
repo := arg.(*StageRepo)
|
||||||
repoURL := repo.URL
|
repoURL := repo.URL
|
||||||
|
|
||||||
|
if pkg, found := packageCache.Get(repoURL); found {
|
||||||
|
lock.Lock()
|
||||||
|
widgets = append(widgets, pkg.(*Widget))
|
||||||
|
lock.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
widget := &Widget{}
|
widget := &Widget{}
|
||||||
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/widget.json"
|
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/widget.json"
|
||||||
innerResp, innerErr := httpclient.NewBrowserRequest().SetSuccessResult(widget).Get(innerU)
|
innerResp, innerErr := httpclient.NewBrowserRequest().SetSuccessResult(widget).Get(innerU)
|
||||||
|
|
@ -93,6 +100,8 @@ func Widgets() (widgets []*Widget) {
|
||||||
lock.Lock()
|
lock.Lock()
|
||||||
widgets = append(widgets, widget)
|
widgets = append(widgets, widget)
|
||||||
lock.Unlock()
|
lock.Unlock()
|
||||||
|
|
||||||
|
packageCache.SetDefault(repoURL, widget)
|
||||||
})
|
})
|
||||||
for _, repo := range stageIndex.Repos {
|
for _, repo := range stageIndex.Repos {
|
||||||
waitGroup.Add(1)
|
waitGroup.Add(1)
|
||||||
|
|
|
||||||
|
|
@ -210,6 +210,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func RefreshCheckJob() {
|
func RefreshCheckJob() {
|
||||||
|
go util.GetRhyResult(true) // 发一次请求进行结果缓存
|
||||||
go refreshSubscriptionExpirationRemind()
|
go refreshSubscriptionExpirationRemind()
|
||||||
go refreshUser()
|
go refreshUser()
|
||||||
go refreshAnnouncement()
|
go refreshAnnouncement()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue