Commit 3a8cd7b7 by Arve Knudsen Committed by Marcus Efraimsson

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
parent 6d70545c
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment