From acdcfcc6ebfe762657aa866ccbb8d9f8bd906639 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 16 Apr 2024 10:59:15 +0800 Subject: [PATCH] Fix cache bug (#30510) Cache cannot be disabled from v1.22. So it still maybe `nil` in v1.21, we have to check whether cache is `nil`. --- services/repository/commitstatus/commitstatus.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/services/repository/commitstatus/commitstatus.go b/services/repository/commitstatus/commitstatus.go index 65d2e3d4686..759f79f7f8f 100644 --- a/services/repository/commitstatus/commitstatus.go +++ b/services/repository/commitstatus/commitstatus.go @@ -32,6 +32,9 @@ type commitStatusCacheValue struct { func getCommitStatusCache(repoID int64, branchName string) *commitStatusCacheValue { c := cache.GetCache() + if c == nil { + return nil + } statusStr, ok := c.Get(getCacheKey(repoID, branchName)).(string) if ok && statusStr != "" { var cv commitStatusCacheValue @@ -48,6 +51,9 @@ func getCommitStatusCache(repoID int64, branchName string) *commitStatusCacheVal func updateCommitStatusCache(repoID int64, branchName string, state api.CommitStatusState, targetURL string) error { c := cache.GetCache() + if c == nil { + return nil + } bs, err := json.Marshal(commitStatusCacheValue{ State: state.String(), TargetURL: targetURL,