Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Apr 12, 2024
2 parents 8cdcc98 + da59fa2 commit 6cb4ec8
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 0 deletions.
9 changes: 9 additions & 0 deletions kernel/bazaar/icon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions kernel/bazaar/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -680,3 +681,5 @@ func disallowDisplayBazaarPackage(pkg *Package) bool {
}
return false
}

var packageCache = gcache.New(6*time.Hour, 30*time.Minute) // [repoURL]*Package
9 changes: 9 additions & 0 deletions kernel/bazaar/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions kernel/bazaar/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions kernel/bazaar/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions kernel/bazaar/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions kernel/model/cloud_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ var (
)

func RefreshCheckJob() {
go util.GetRhyResult(true) // 发一次请求进行结果缓存
go refreshSubscriptionExpirationRemind()
go refreshUser()
go refreshAnnouncement()
Expand Down

0 comments on commit 6cb4ec8

Please sign in to comment.