aboutsummaryrefslogtreecommitdiffstats
path: root/services/repository/branch.go
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-04-13 16:38:44 +0800
committerGitHub <noreply@github.com>2024-04-13 08:38:44 +0000
commitc248f010ad08a7017ba1d418e9b6a5b72aff0c88 (patch)
tree4e479229bc1248e123f2ed9296edf80fe96cdd65 /services/repository/branch.go
parent8fd8978b4934865c2b041216e84e923ad574a4c7 (diff)
downloadgitea-c248f010ad08a7017ba1d418e9b6a5b72aff0c88.tar.gz
gitea-c248f010ad08a7017ba1d418e9b6a5b72aff0c88.zip
Refactor cache and disable go-chi cache (#30417)
use built-in cache package to wrap external go-chi cache package
Diffstat (limited to 'services/repository/branch.go')
-rw-r--r--services/repository/branch.go11
1 files changed, 5 insertions, 6 deletions
diff --git a/services/repository/branch.go b/services/repository/branch.go
index 229ac54f30..d74e5819a1 100644
--- a/services/repository/branch.go
+++ b/services/repository/branch.go
@@ -26,6 +26,7 @@ import (
"code.gitea.io/gitea/modules/queue"
repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/timeutil"
+ "code.gitea.io/gitea/modules/util"
webhook_module "code.gitea.io/gitea/modules/webhook"
notify_service "code.gitea.io/gitea/services/notify"
files_service "code.gitea.io/gitea/services/repository/files"
@@ -119,17 +120,15 @@ func getDivergenceCacheKey(repoID int64, branchName string) string {
// getDivergenceFromCache gets the divergence from cache
func getDivergenceFromCache(repoID int64, branchName string) (*git.DivergeObject, bool) {
- data := cache.GetCache().Get(getDivergenceCacheKey(repoID, branchName))
+ data, ok := cache.GetCache().Get(getDivergenceCacheKey(repoID, branchName))
res := git.DivergeObject{
Ahead: -1,
Behind: -1,
}
- s, ok := data.([]byte)
- if !ok || len(s) == 0 {
+ if !ok || data == "" {
return &res, false
}
-
- if err := json.Unmarshal(s, &res); err != nil {
+ if err := json.Unmarshal(util.UnsafeStringToBytes(data), &res); err != nil {
log.Error("json.UnMarshal failed: %v", err)
return &res, false
}
@@ -141,7 +140,7 @@ func putDivergenceFromCache(repoID int64, branchName string, divergence *git.Div
if err != nil {
return err
}
- return cache.GetCache().Put(getDivergenceCacheKey(repoID, branchName), bs, 30*24*60*60)
+ return cache.GetCache().Put(getDivergenceCacheKey(repoID, branchName), util.UnsafeBytesToString(bs), 30*24*60*60)
}
func DelDivergenceFromCache(repoID int64, branchName string) error {