Skip to content

Commit

Permalink
Fix cache bug (#30510)
Browse files Browse the repository at this point in the history
Cache cannot be disabled from v1.22. So it still maybe `nil` in v1.21,
we have to check whether cache is `nil`.
  • Loading branch information
lunny authored Apr 16, 2024
1 parent 727b191 commit acdcfcc
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions services/repository/commitstatus/commitstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit acdcfcc

Please sign in to comment.