mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Avatar: Don't log failure to add existing item to cache (#19947)
Checks if avatar was found in cache before trying to add it to cache. Fixes #19946
This commit is contained in:
parent
6d70545c07
commit
3a8cd7b76c
@ -88,14 +88,15 @@ func (this *CacheServer) Handler(ctx *macaron.Context) {
|
||||
hash := urlPath[strings.LastIndex(urlPath, "/")+1:]
|
||||
|
||||
var avatar *Avatar
|
||||
|
||||
if obj, exist := this.cache.Get(hash); exist {
|
||||
obj, exists := this.cache.Get(hash)
|
||||
if exists {
|
||||
avatar = obj.(*Avatar)
|
||||
} else {
|
||||
avatar = New(hash)
|
||||
}
|
||||
|
||||
if avatar.Expired() {
|
||||
// The cache item is either expired or newly created, update it from the server
|
||||
if err := avatar.Update(); err != nil {
|
||||
log.Trace("avatar update error: %v", err)
|
||||
avatar = this.notFound
|
||||
@ -104,9 +105,9 @@ func (this *CacheServer) Handler(ctx *macaron.Context) {
|
||||
|
||||
if avatar.notFound {
|
||||
avatar = this.notFound
|
||||
} else {
|
||||
} else if !exists {
|
||||
if err := this.cache.Add(hash, avatar, gocache.DefaultExpiration); err != nil {
|
||||
log.Warn("Error adding avatar to cache: %s", err)
|
||||
log.Trace("Error adding avatar to cache: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,7 +222,6 @@ func (this *thunderTask) fetch() error {
|
||||
req.Header.Set("Cache-Control", "no-cache")
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36")
|
||||
resp, err := client.Do(req)
|
||||
|
||||
if err != nil {
|
||||
this.Avatar.notFound = true
|
||||
return fmt.Errorf("gravatar unreachable, %v", err)
|
||||
|
Loading…
Reference in New Issue
Block a user