From 3a8cd7b76cb5b3883c830820483a3c2dc192f96a Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Tue, 12 Nov 2019 18:49:09 +0100 Subject: [PATCH] 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 --- pkg/api/avatar/avatar.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/api/avatar/avatar.go b/pkg/api/avatar/avatar.go index 2ab957c1957..ffbb51dd498 100644 --- a/pkg/api/avatar/avatar.go +++ b/pkg/api/avatar/avatar.go @@ -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)