mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-31 19:38:23 +00:00 
			
		
		
		
	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`.
This commit is contained in:
		| @@ -32,6 +32,9 @@ type commitStatusCacheValue struct { | |||||||
|  |  | ||||||
| func getCommitStatusCache(repoID int64, branchName string) *commitStatusCacheValue { | func getCommitStatusCache(repoID int64, branchName string) *commitStatusCacheValue { | ||||||
| 	c := cache.GetCache() | 	c := cache.GetCache() | ||||||
|  | 	if c == nil { | ||||||
|  | 		return nil | ||||||
|  | 	} | ||||||
| 	statusStr, ok := c.Get(getCacheKey(repoID, branchName)).(string) | 	statusStr, ok := c.Get(getCacheKey(repoID, branchName)).(string) | ||||||
| 	if ok && statusStr != "" { | 	if ok && statusStr != "" { | ||||||
| 		var cv commitStatusCacheValue | 		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 { | func updateCommitStatusCache(repoID int64, branchName string, state api.CommitStatusState, targetURL string) error { | ||||||
| 	c := cache.GetCache() | 	c := cache.GetCache() | ||||||
|  | 	if c == nil { | ||||||
|  | 		return nil | ||||||
|  | 	} | ||||||
| 	bs, err := json.Marshal(commitStatusCacheValue{ | 	bs, err := json.Marshal(commitStatusCacheValue{ | ||||||
| 		State:     state.String(), | 		State:     state.String(), | ||||||
| 		TargetURL: targetURL, | 		TargetURL: targetURL, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user