Parcourir la source

Merge remote-tracking branch 'origin/dev' into dev

Vanessa il y a 1 an
Parent
commit
6cb4ec8777

+ 9 - 0
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)

+ 3 - 0
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

+ 9 - 0
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)

+ 9 - 0
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)

+ 9 - 0
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)

+ 9 - 0
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)

+ 1 - 0
kernel/model/cloud_service.go

@@ -210,6 +210,7 @@ var (
 )
 
 func RefreshCheckJob() {
+	go util.GetRhyResult(true) // 发一次请求进行结果缓存
 	go refreshSubscriptionExpirationRemind()
 	go refreshUser()
 	go refreshAnnouncement()